-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathApplicationTest.php
More file actions
148 lines (119 loc) · 4.31 KB
/
ApplicationTest.php
File metadata and controls
148 lines (119 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
require_once codecept_data_dir() . 'TestedRoboFile.php';
use Robo\Robo;
use Consolidation\AnnotatedCommand\Parser\CommandInfo;
use Robo\Collection\CollectionBuilder;
class ApplicationTest extends \Codeception\TestCase\Test
{
/**
* @var \Robo\Runner
*/
private $runner;
/**
* @var \Robo\Application
*/
private $app;
/**
* @var Consolidation\AnnotatedCommand\AnnotatedCommandFactory
*/
private $commandFactory;
/**
* @var TestRoboFile
*/
private $roboCommandFileInstance;
protected function _before()
{
$container = Robo::createDefaultContainer();
$this->app = $container->get('application');
$config = $container->get('config');
$this->commandFactory = $container->get('commandFactory');
$this->roboCommandFileInstance = new TestedRoboFile;
$builder = CollectionBuilder::create($container, $this->roboCommandFileInstance);
$this->roboCommandFileInstance->setBuilder($builder);
$commandList = $this->commandFactory->createCommandsFromClass($this->roboCommandFileInstance);
foreach ($commandList as $command) {
$this->app->addCommand($command);
}
}
public function testTaskAccessor()
{
// Get a reference to the protected 'task' method, as
// this is normally only callable by methods of the
// commandfile instance.
$method = new ReflectionMethod($this->roboCommandFileInstance, 'task');
if (\PHP_VERSION_ID < 80100) {
$method->setAccessible(true);
}
$collectionBuilder = $method->invoke($this->roboCommandFileInstance, 'Robo\Task\Base\Exec', 'ls');
$this->assertEquals(
'Robo\Collection\CollectionBuilder',
get_class($collectionBuilder));
$task = $collectionBuilder->getCollectionBuilderCurrentTask();
$this->assertEquals(
'Robo\Task\Base\Exec',
get_class($task));
$this->assertEquals(
'Robo\Task\Base\Exec',
get_class($task));
}
public function testAllowEmptyValuesAsDefaultsToOptionalOptions()
{
$command = $this->createCommand('hello');
$yell = $command->getDefinition()->getOption('yell');
$this->assertFalse($yell->isValueOptional());
$this->assertFalse($yell->getDefault());
$to = $command->getDefinition()->getOption('to');
$this->assertTrue($to->isValueOptional());
$this->assertNull($to->getDefault());
}
public function testCommandDocumentation()
{
$command = $this->createCommand('fibonacci');
$this->assertEquals(
'Calculate the fibonacci sequence between two numbers.',
$command->getDescription());
}
public function testCommandCompactDocumentation()
{
$command = $this->createCommand('compact');
$this->assertEquals(
'Compact doc comment',
$command->getDescription());
}
public function testCommandArgumentDocumentation()
{
$command = $this->createCommand('fibonacci');
$start = $command->getDefinition()->getArgument('start');
$this->assertEquals(
'Number to start from',
$start->getDescription());
$steps = $command->getDefinition()->getArgument('steps');
$this->assertEquals(
'Number of steps to perform',
$steps->getDescription());
}
public function testCommandOptionDocumentation()
{
$command = $this->createCommand('fibonacci');
$graphic = $command->getDefinition()->getOption('graphic');
$this->assertEquals(
'Display the sequence graphically using cube representation',
$graphic->getDescription());
}
public function testCommandHelpDocumentation()
{
$command = $this->createCommand('fibonacci');
$this->assertContains(
'+----+---+',
$command->getHelp());
}
public function testCommandNaming()
{
$this->assertNotNull($this->app->find('generate:user-avatar'));
}
protected function createCommand($name)
{
$commandInfo = new CommandInfo($this->roboCommandFileInstance, $name);
return $this->commandFactory->createCommand($commandInfo, $this->roboCommandFileInstance);
}
}