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 assertCommandInfoIsAsExpected($commandInfo)
41 $this->assertEquals('test:arithmatic', $commandInfo->getName());
43 'This is the test:arithmatic command',
44 $commandInfo->getDescription()
47 "This command will add one and two. If the --negate flag\nis provided, then the result is negated.",
48 $commandInfo->getHelp()
50 $this->assertEquals('arithmatic', implode(',', $commandInfo->getAliases()));
52 '2 2 --negate=>Add two plus two and then negate.',
53 $this->flattenArray($commandInfo->getExampleUsages())
56 'The first number to add.',
57 $commandInfo->arguments()->getDescription('one')
60 'The other number to add.',
61 $commandInfo->arguments()->getDescription('two')
65 $commandInfo->arguments()->get('two')
68 'Whether or not the result should be negated.',
69 $commandInfo->options()->getDescription('negate')
73 $commandInfo->options()->get('unused')
77 $commandInfo->getAnnotation('dup')
81 $commandInfo->getAnnotationList('dup')
85 function testReturnValue()
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());