ApplicationTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 9
dl 0
loc 139
c 0
b 0
f 0
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A _before() 0 15 2
A testTaskAccessor() 0 19 1
A testAllowEmptyValuesAsDefaultsToOptionalOptions() 0 14 1
A testCommandDocumentation() 0 8 1
A testCommandCompactDocumentation() 0 8 1
A testCommandArgumentDocumentation() 0 16 1
A testCommandOptionDocumentation() 0 10 1
A testCommandHelpDocumentation() 0 8 1
A testCommandNaming() 0 4 1
A createCommand() 0 5 1
1
<?php
2
require_once codecept_data_dir() . 'TestedRoboFile.php';
3
4
use Robo\Robo;
5
use Consolidation\AnnotatedCommand\Parser\CommandInfo;
6
use Robo\Collection\CollectionBuilder;
7
8
class ApplicationTest extends \Codeception\TestCase\Test
9
{
10
    /**
11
     * @var \Robo\Runner
12
     */
13
    private $runner;
14
15
    /**
16
     * @var \Robo\Application
17
     */
18
    private $app;
19
20
    /**
21
     * @var Consolidation\AnnotatedCommand\AnnotatedCommandFactory
22
     */
23
    private $commandFactory;
24
25
    /**
26
     * @var TestRoboFile
27
     */
28
    private $roboCommandFileInstance;
29
30
    protected function _before()
31
    {
32
        $container = Robo::createDefaultContainer();
33
34
        $this->app = $container->get('application');
35
        $config = $container->get('config');
0 ignored issues
show
Unused Code introduced by
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
36
        $this->commandFactory = $container->get('commandFactory');
37
        $this->roboCommandFileInstance = new TestedRoboFile;
0 ignored issues
show
Documentation Bug introduced by
It seems like new \TestedRoboFile() of type object<TestedRoboFile> is incompatible with the declared type object<TestRoboFile> of property $roboCommandFileInstance.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
        $builder = CollectionBuilder::create($container, $this->roboCommandFileInstance);
39
        $this->roboCommandFileInstance->setBuilder($builder);
40
        $commandList = $this->commandFactory->createCommandsFromClass($this->roboCommandFileInstance);
41
        foreach ($commandList as $command) {
42
            $this->app->add($command);
43
        }
44
    }
45
46
    public function testTaskAccessor()
47
    {
48
        // Get a reference to the protected 'task' method, as
49
        // this is normally only callable by methods of the
50
        // commandfile instance.
51
        $method = new ReflectionMethod($this->roboCommandFileInstance, 'task');
52
        $method->setAccessible(true);
53
        $collectionBuilder = $method->invoke($this->roboCommandFileInstance, 'Robo\Task\Base\Exec', 'ls');
54
        $this->assertEquals(
55
            'Robo\Collection\CollectionBuilder',
56
            get_class($collectionBuilder));
57
        $task = $collectionBuilder->getCollectionBuilderCurrentTask();
58
        $this->assertEquals(
59
            'Robo\Task\Base\Exec',
60
            get_class($task));
61
        $this->assertEquals(
62
            'Robo\Task\Base\Exec',
63
            get_class($task));
64
    }
65
66
    public function testAllowEmptyValuesAsDefaultsToOptionalOptions()
67
    {
68
        $command = $this->createCommand('hello');
69
70
        $yell = $command->getDefinition()->getOption('yell');
71
72
        $this->assertFalse($yell->isValueOptional());
73
        $this->assertFalse($yell->getDefault());
74
75
        $to = $command->getDefinition()->getOption('to');
76
77
        $this->assertTrue($to->isValueOptional());
78
        $this->assertNull($to->getDefault());
79
    }
80
81
    public function testCommandDocumentation()
82
    {
83
        $command = $this->createCommand('fibonacci');
84
85
        $this->assertEquals(
86
            'Calculate the fibonacci sequence between two numbers.',
87
            $command->getDescription());
88
    }
89
90
    public function testCommandCompactDocumentation()
91
    {
92
        $command = $this->createCommand('compact');
93
94
        $this->assertEquals(
95
            'Compact doc comment',
96
            $command->getDescription());
97
    }
98
99
    public function testCommandArgumentDocumentation()
100
    {
101
        $command = $this->createCommand('fibonacci');
102
103
        $start = $command->getDefinition()->getArgument('start');
104
105
        $this->assertEquals(
106
            'Number to start from',
107
            $start->getDescription());
108
109
        $steps = $command->getDefinition()->getArgument('steps');
110
111
        $this->assertEquals(
112
            'Number of steps to perform',
113
            $steps->getDescription());
114
    }
115
116
    public function testCommandOptionDocumentation()
117
    {
118
        $command = $this->createCommand('fibonacci');
119
120
        $graphic = $command->getDefinition()->getOption('graphic');
121
122
        $this->assertEquals(
123
            'Display the sequence graphically using cube representation',
124
            $graphic->getDescription());
125
    }
126
127
    public function testCommandHelpDocumentation()
128
    {
129
        $command = $this->createCommand('fibonacci');
130
131
        $this->assertContains(
132
            '+----+---+',
133
            $command->getHelp());
134
    }
135
136
    public function testCommandNaming()
137
    {
138
        $this->assertNotNull($this->app->find('generate:user-avatar'));
139
    }
140
141
    protected function createCommand($name)
142
    {
143
        $commandInfo = new CommandInfo($this->roboCommandFileInstance, $name);
144
        return $this->commandFactory->createCommand($commandInfo, $this->roboCommandFileInstance);
145
    }
146
}
147