722126756f220ba35ee8ed951614a5478d9c2e1d
[yaffs-website] / vendor / consolidation / annotated-command / tests / testCommandInfo.php
1 <?php
2 namespace Consolidation\AnnotatedCommand;
3
4 use Consolidation\AnnotatedCommand\Parser\CommandInfo;
5 use Consolidation\AnnotatedCommand\Parser\CommandInfoSerializer;
6 use Consolidation\AnnotatedCommand\Parser\CommandInfoDeserializer;
7
8 class CommandInfoTests extends \PHPUnit_Framework_TestCase
9 {
10     function flattenArray($actualValue)
11     {
12         $result = [];
13         foreach ($actualValue as $key => $value) {
14           if (!is_string($value)) {
15               $value = var_export($value, true);
16           }
17           $result[] = "{$key}=>{$value}";
18         }
19         return implode("\n", $result);
20     }
21
22     /**
23      * Test CommandInfo command annotation parsing.
24      */
25     function testParsing()
26     {
27         $commandInfo = CommandInfo::create('\Consolidation\TestUtils\ExampleCommandFile', 'testArithmatic');
28         $this->assertCommandInfoIsAsExpected($commandInfo);
29
30         $serializer = new CommandInfoSerializer();
31         $serialized = $serializer->serialize($commandInfo);
32
33         $deserializer = new CommandInfoDeserializer();
34
35         $deserializedCommandInfo = $deserializer->deserialize($serialized);
36         $this->assertCommandInfoIsAsExpected($deserializedCommandInfo);
37     }
38
39     function assertCommandInfoIsAsExpected($commandInfo)
40     {
41         $this->assertEquals('test:arithmatic', $commandInfo->getName());
42         $this->assertEquals(
43             'This is the test:arithmatic command',
44             $commandInfo->getDescription()
45         );
46         $this->assertEquals(
47             "This command will add one and two. If the --negate flag\nis provided, then the result is negated.",
48             $commandInfo->getHelp()
49         );
50         $this->assertEquals('arithmatic', implode(',', $commandInfo->getAliases()));
51         $this->assertEquals(
52             '2 2 --negate=>Add two plus two and then negate.',
53             $this->flattenArray($commandInfo->getExampleUsages())
54         );
55         $this->assertEquals(
56             'The first number to add.',
57             $commandInfo->arguments()->getDescription('one')
58         );
59         $this->assertEquals(
60             'The other number to add.',
61             $commandInfo->arguments()->getDescription('two')
62         );
63         $this->assertEquals(
64             '2',
65             $commandInfo->arguments()->get('two')
66         );
67         $this->assertEquals(
68             'Whether or not the result should be negated.',
69             $commandInfo->options()->getDescription('negate')
70         );
71         $this->assertEquals(
72             'bob',
73             $commandInfo->options()->get('unused')
74         );
75         $this->assertEquals(
76             'one,two',
77             $commandInfo->getAnnotation('dup')
78         );
79         $this->assertEquals(
80             ['one','two'],
81             $commandInfo->getAnnotationList('dup')
82         );
83     }
84
85     function testReturnValue()
86     {
87         $commandInfo = CommandInfo::create('\Consolidation\TestUtils\alpha\AlphaCommandFile', 'exampleTable');
88         $this->assertEquals('example:table', $commandInfo->getName());
89         $this->assertEquals('\Consolidation\OutputFormatters\StructuredData\RowsOfFields', $commandInfo->getReturnType());
90     }
91 }