|
1
|
|
|
<?php |
|
2
|
|
|
namespace Naneau\FileGen\Test\Console; |
|
3
|
|
|
|
|
4
|
|
|
use Naneau\FileGen\Console\Helper\ParameterHelper; |
|
5
|
|
|
|
|
6
|
|
|
use Naneau\FileGen\Structure; |
|
7
|
|
|
|
|
8
|
|
|
use Naneau\FileGen\Test\Console\ParameterCommand; |
|
9
|
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Application; |
|
11
|
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
|
13
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
|
14
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Testing the parameter helper |
|
18
|
|
|
*/ |
|
19
|
|
|
class ParameterHelperTest extends \PHPUnit\Framework\TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testExecute() |
|
22
|
|
|
{ |
|
23
|
|
|
$application = new Application(); |
|
24
|
|
|
$application->getHelperSet()->set(new ParameterHelper, 'filegenParameters'); |
|
25
|
|
|
|
|
26
|
|
|
$command = new ParameterCommand; |
|
27
|
|
|
$application->add($command); |
|
28
|
|
|
|
|
29
|
|
|
$structure = new Structure; |
|
30
|
|
|
$structure |
|
31
|
|
|
->parameter('foo', 'foo description') |
|
32
|
|
|
->parameter('bar', 'bar description') |
|
33
|
|
|
->parameter('baz', 'baz description'); |
|
34
|
|
|
|
|
35
|
|
|
$structure->getParameterDefinition()->get('baz')->setDefaultValue('BazValue'); |
|
36
|
|
|
|
|
37
|
|
|
$command->setStructure($structure); |
|
38
|
|
|
|
|
39
|
|
|
$commandTester = new CommandTester($command); |
|
40
|
|
|
|
|
41
|
|
|
// Set the input stream |
|
42
|
|
|
$helper = $command->getHelper('question'); |
|
43
|
|
|
$helper->setInputStream( |
|
44
|
|
|
$this->getInputStream("FooValue\nBarValue\n\n") |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$commandTester->execute(array( |
|
48
|
|
|
'command' => $command->getName()) |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertEquals( |
|
52
|
|
|
'foo descriptionbar descriptionbaz description', |
|
53
|
|
|
$commandTester->getDisplay() |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$received = $command->getReceived(); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertArrayHasKey('foo', $received); |
|
59
|
|
|
$this->assertEquals('FooValue', $received['foo']); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertArrayHasKey('bar', $received); |
|
62
|
|
|
$this->assertEquals('BarValue', $received['bar']); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertArrayHasKey('baz', $received); |
|
65
|
|
|
$this->assertEquals('BazValue', $received['baz']); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get input stream |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $input |
|
72
|
|
|
* @return resource |
|
73
|
|
|
**/ |
|
74
|
|
|
protected function getInputStream($input) |
|
75
|
|
|
{ |
|
76
|
|
|
$stream = fopen('php://memory', 'r+', false); |
|
77
|
|
|
fputs($stream, $input); |
|
78
|
|
|
rewind($stream); |
|
79
|
|
|
|
|
80
|
|
|
return $stream; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|