2 namespace Consolidation\AnnotatedCommand;
4 use Consolidation\AnnotatedCommand\Parser\CommandInfo;
5 use Consolidation\AnnotatedCommand\Parser\CommandInfoSerializer;
6 use Consolidation\AnnotatedCommand\Parser\CommandInfoDeserializer;
8 class CommandInfoTests extends \PHPUnit_Framework_TestCase
10 function flattenArray($actualValue)
13 foreach ($actualValue as $key => $value) {
14 if (!is_string($value)) {
15 $value = var_export($value, true);
17 $result[] = "{$key}=>{$value}";
19 return implode("\n", $result);
23 * Test CommandInfo command annotation parsing.
25 function testParsing()
27 $commandInfo = CommandInfo::create('\Consolidation\TestUtils\ExampleCommandFile', 'testArithmatic');
28 $this->assertCommandInfoIsAsExpected($commandInfo);
30 $serializer = new CommandInfoSerializer();
31 $serialized = $serializer->serialize($commandInfo);
33 $deserializer = new CommandInfoDeserializer();
35 $deserializedCommandInfo = $deserializer->deserialize($serialized);
36 $this->assertCommandInfoIsAsExpected($deserializedCommandInfo);
39 function testWithConfigImport()
41 $commandInfo = CommandInfo::create('\Consolidation\TestUtils\ExampleCommandFile', 'import');
42 $this->assertEquals('config:import', $commandInfo->getName());
45 'A config directory label (i.e. a key in \$config_directories array in settings.php).',
46 $commandInfo->arguments()->getDescription('label')
50 function assertCommandInfoIsAsExpected($commandInfo)
52 $this->assertEquals('test:arithmatic', $commandInfo->getName());
54 'This is the test:arithmatic command',
55 $commandInfo->getDescription()
58 "This command will add one and two. If the --negate flag\nis provided, then the result is negated.",
59 $commandInfo->getHelp()
61 $this->assertEquals('arithmatic', implode(',', $commandInfo->getAliases()));
63 '2 2 --negate=>Add two plus two and then negate.',
64 $this->flattenArray($commandInfo->getExampleUsages())
67 'The first number to add.',
68 $commandInfo->arguments()->getDescription('one')
71 'The other number to add.',
72 $commandInfo->arguments()->getDescription('two')
76 $commandInfo->arguments()->get('two')
79 'Whether or not the result should be negated.',
80 $commandInfo->options()->getDescription('negate')
84 $commandInfo->options()->get('unused')
88 $commandInfo->getAnnotation('dup')
92 $commandInfo->getAnnotationList('dup')
96 function testReturnValue()
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());