ImplementContext   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 10
lcom 1
cbo 6
dl 0
loc 105
rs 10
c 1
b 0
f 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setup() 0 8 1
A setupCommand() 0 10 1
A iTypeABehaviorImplementCommand() 0 4 1
A iTypeAPhpspecBehaviorImplementCommandWithoutArguments() 0 4 1
A getImplementCommand() 0 8 2
A createImplementCommand() 0 11 1
A getConfigurator() 0 6 2
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\Context\Console\Command;
11
12
use Tidal\PhpSpec\BehaviorExtension\Console\Command\ImplementCommand;
13
14
use features\Behavior\Context\Console\SelectCommandContextTrait;
15
16
use Behat\Behat\Tester\Exception\PendingException;
17
use Behat\Behat\Context\Context;
18
use Tidal\PhpSpec\ConsoleExtension\Command\InlineConfigurator as Configurator;
19
use Tidal\PhpSpec\ConsoleExtension\Contract\Command\ConfigInterface as CommandConfig;
20
21
22
class ImplementContext implements Context
23
{
24
    use  SelectCommandContextTrait;
25
26
    const COMMAND_NAME = 'behavior:implement';
27
28
    /**
29
     * @var ImplementCommand
30
     */
31
    private $implementCommand;
32
33
    /**
34
     * @var Configurator
35
     */
36
    private $configurator;
37
38
    /**
39
     * Initializes context.
40
     *
41
     * Every scenario gets its own context instance.
42
     * You can also pass arbitrary arguments to the
43
     * context constructor through behat.yml.
44
     */
45
    public function __construct()
46
    {
47
    }
48
49
    /**
50
     * @beforeScenario
51
     */
52
    public function setup()
53
    {
54
        $this->resetApplication();
55
        $this->resetCommand();
56
        $this->setupApplication();
57
        $this->setupCommand();
58
59
    }
60
61
    private function setupCommand()
62
    {
63
        $this->setCommand(
64
            $this->getImplementCommand()
65
        );
66
        $this->getApplication()
67
            ->add(
68
                $this->getCommand()
69
            );
70
    }
71
72
73
    /**
74
     * @Given I type a behavior implement command
75
     * @Given I type a phpspec behavior implement command
76
     */
77
    public function iTypeABehaviorImplementCommand()
78
    {
79
        $this->setupCommand();
80
    }
81
82
    /**
83
     * @Given I type a behavior implement command without Arguments
84
     * @Given I type a phpspec behavior implement command without Arguments
85
     */
86
    public function iTypeAPhpspecBehaviorImplementCommandWithoutArguments()
87
    {
88
        throw new PendingException();
89
    }
90
91
    /**
92
     * @return ImplementCommand
93
     */
94
    public function getImplementCommand(): ImplementCommand
95
    {
96
        if (!isset($this->implementCommand)) {
97
            $this->createImplementCommand();
98
        }
99
100
        return $this->implementCommand;
101
    }
102
103
    private function createImplementCommand()
104
    {
105
        $this->implementCommand = new ImplementCommand(
106
            $this->getWriter(),
107
            $this->getConfigurator(),
108
            [CommandConfig::NAME_KEY => self::COMMAND_NAME]
109
        );
110
        $this->implementCommand->setContainer(
111
            $this->createContainerProphecy()->reveal()
112
        );
113
    }
114
115
    /**
116
     * @return Configurator
117
     */
118
    public function getConfigurator(): Configurator
119
    {
120
        return isset($this->configurator)
121
            ? $this->configurator
122
            : $this->configurator = new Configurator();
123
    }
124
125
126
}
127