More updates to stop using dev or alpha or beta versions.
[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 testWithConfigImport()
40     {
41         $commandInfo = CommandInfo::create('\Consolidation\TestUtils\ExampleCommandFile', 'import');
42         $this->assertEquals('config:import', $commandInfo->getName());
43
44         $this->assertEquals(
45             'A config directory label (i.e. a key in \$config_directories array in settings.php).',
46             $commandInfo->arguments()->getDescription('label')
47         );
48     }
49
50     function assertCommandInfoIsAsExpected($commandInfo)
51     {
52         $this->assertEquals('test:arithmatic', $commandInfo->getName());
53         $this->assertEquals(
54             'This is the test:arithmatic command',
55             $commandInfo->getDescription()
56         );
57         $this->assertEquals(
58             "This command will add one and two. If the --negate flag\nis provided, then the result is negated.",
59             $commandInfo->getHelp()
60         );
61         $this->assertEquals('arithmatic', implode(',', $commandInfo->getAliases()));
62         $this->assertEquals(
63             '2 2 --negate=>Add two plus two and then negate.',
64             $this->flattenArray($commandInfo->getExampleUsages())
65         );
66         $this->assertEquals(
67             'The first number to add.',
68             $commandInfo->arguments()->getDescription('one')
69         );
70         $this->assertEquals(
71             'The other number to add.',
72             $commandInfo->arguments()->getDescription('two')
73         );
74         $this->assertEquals(
75             '2',
76             $commandInfo->arguments()->get('two')
77         );
78         $this->assertEquals(
79             'Whether or not the result should be negated.',
80             $commandInfo->options()->getDescription('negate')
81         );
82         $this->assertEquals(
83             'bob',
84             $commandInfo->options()->get('unused')
85         );
86         $this->assertEquals(
87             'one,two',
88             $commandInfo->getAnnotation('dup')
89         );
90         $this->assertEquals(
91             ['one','two'],
92             $commandInfo->getAnnotationList('dup')
93         );
94     }
95
96     function testReturnValue()
97     {
98         $commandInfo = CommandInfo::create('\Consolidation\TestUtils\alpha\AlphaCommandFile', 'exampleTable');
99         $this->assertEquals('example:table', $commandInfo->getName());
100         $this->assertEquals('\Consolidation\OutputFormatters\StructuredData\RowsOfFields', $commandInfo->getReturnType());
101     }
102 }