selectedCommandHasArgument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
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\Context\Console;
11
12
use Symfony\Component\Console\Command\Command;
13
14
use Hamcrest\MatcherAssert as Matcher;
15
16
/**
17
 * Trait features\Behavior\Context\Console\SelectCommandContextTrait */
18
trait SelectCommandContextTrait
19
{
20
    use CommandContextTrait;
21
22
    /**
23
     * @var Command
24
     */
25
    protected $selectedCommand;
26
27
28
    /**
29
     * @Given I select command :command in namespace :namespace
30
     *
31
     * @param string $command
32
     * @param null|string $namespace
33
     */
34
    public function iSelectCommandInNamespace(string $command, ?string $namespace)
35
    {
36
        $this->selectedCommand = $this->getApplication()
37
            ->find(
38
                $this->renderCommandName(
39
                    $command,
40
                    $namespace
41
                )
42
            );
43
    }
44
45
    /**
46
     * @Given selected command has argument :argument
47
     *
48
     * @param string $argument
49
     */
50
    public function selectedCommandHasArgument(string $argument)
51
    {
52
        $this->assertSelectedCommand();
53
54
        Matcher::assertThat(
55
            sprintf(
56
                "selected command should have argument '%s'",
57
                $argument
58
            ),
59
            $this->selectedCommand
60
                ->getDefinition()
61
                ->hasArgument($argument)
62
        );
63
    }
64
65
    /**
66
     * @Given selected command has option :option
67
     *
68
     * @param string $option
69
     */
70
    public function selectedCommandHasOption(string $option)
71
    {
72
        $this->assertSelectedCommand();
73
74
        Matcher::assertThat(
75
            sprintf(
76
                "selected command should have option '%s'",
77
                $option
78
            ),
79
            $this->selectedCommand
80
                ->getDefinition()
81
                ->hasOption($option)
82
        );
83
    }
84
85
    protected function assertSelectedCommand()
86
    {
87
        Matcher::assertThat(
88
            'A command should be selected',
89
            isset($this->selectedCommand)
90
        );
91
    }
92
93
}