ApplicationTestTrait::getApplicationTester()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
/**
3
 * This file is part of the phpspec-behavior package.
4
 * (c) 2017 Timo Michna <timomichna/yahoo.de>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace features\Behavior\Console;
11
12
use PhpSpec\Console\Application as PhpSpecApp;
13
14
use Symfony\Component\Console\Application;
15
use Symfony\Component\Console\Tester\ApplicationTester;
16
17
trait ApplicationTestTrait
18
{
19
    /**
20
     * @var Application
21
     */
22
    protected $application;
23
24
    /**
25
     * @var ApplicationTester
26
     */
27
    protected $applicationTester;
28
29
    /**
30
     * @var string
31
     */
32
    protected $applicationName;
33
34
    public function setupApplication()
35
    {
36
        $this->applicationName = $this->getApplication()->getName();
37
    }
38
39
    /**
40
     * @param Application $application
41
     */
42
    public function setApplication(Application $application)
43
    {
44
        $this->application = $application;
45
    }
46
47
    /**
48
     * @return Application
49
     */
50
    public function getApplication(): Application
51
    {
52
        if (!isset($this->application)) {
53
            $this->createApplication();
54
        }
55
56
        return $this->application;
57
    }
58
59
    private function createApplication()
60
    {
61
        $this->application = new PhpSpecApp('dev');
62
        $this->application->setAutoExit(false);
63
    }
64
65
    protected function resetApplication()
66
    {
67
        $this->application = null;
68
        $this->applicationTester = null;
69
    }
70
71
    /**
72
     * @param ApplicationTester $applicationTester
73
     */
74
    public function setApplicationTester(ApplicationTester $applicationTester)
75
    {
76
        $this->applicationTester = $applicationTester;
77
    }
78
79
    /**
80
     * @return ApplicationTester
81
     */
82
    public function getApplicationTester(): ApplicationTester
83
    {
84
        if (!isset($this->applicationTester)) {
85
            $this->createApplicationTester();
86
        }
87
88
        return $this->applicationTester;
89
    }
90
91
    private function createApplicationTester()
92
    {
93
        $this->applicationTester = new ApplicationTester(
94
            $this->getApplication()
95
        );
96
    }
97
}