887300ed7229f37406e8b4a8cfca9960a571a276
[yaffs-website] / vendor / consolidation / annotated-command / tests / testAnnotatedCommand.php
1 <?php
2 namespace Consolidation\AnnotatedCommand;
3
4 use Symfony\Component\Console\Command\Command;
5 use Symfony\Component\Console\Input\InputInterface;
6 use Symfony\Component\Console\Output\OutputInterface;
7 use Symfony\Component\Console\Input\StringInput;
8 use Symfony\Component\Console\Output\BufferedOutput;
9 use Symfony\Component\Console\Application;
10
11 class AnnotatedCommandTests extends \PHPUnit_Framework_TestCase
12 {
13     function testMyCatCommand()
14     {
15         $command = new \Consolidation\TestUtils\ExampleAnnotatedCommand();
16
17         $this->assertInstanceOf('\Symfony\Component\Console\Command\Command', $command);
18         $this->assertEquals('my:cat', $command->getName());
19         $this->assertEquals('This is the my:cat command implemented as an AnnotatedCommand subclass.', $command->getDescription());
20         $this->assertEquals("This command will concatenate two parameters. If the --flip flag\nis provided, then the result is the concatenation of two and one.", $command->getHelp());
21         $this->assertEquals('c', implode(',', $command->getAliases()));
22         // Symfony Console composes the synopsis; perhaps we should not test it. Remove if this gives false failures.
23         $this->assertEquals('my:cat [--multiple MULTIPLE] [--flip] [--] <one> [<two>]', $command->getSynopsis());
24         $this->assertEquals('my:cat bet alpha --flip', implode(',', $command->getUsages()));
25
26         $input = new StringInput('my:cat b alpha --multiple=t --multiple=e --flip');
27         $this->assertRunCommandViaApplicationEquals($command, $input, 'alphabet');
28     }
29
30     // TODO: Make a base test class to hold this.
31     function assertRunCommandViaApplicationEquals($command, $input, $expectedOutput, $expectedStatusCode = 0)
32     {
33         $output = new BufferedOutput();
34
35         $application = new Application('TestApplication', '0.0.0');
36         $application->setAutoExit(false);
37         $application->add($command);
38
39         $statusCode = $application->run($input, $output);
40         $commandOutput = trim($output->fetch());
41
42         $this->assertEquals($expectedOutput, $commandOutput);
43         $this->assertEquals($expectedStatusCode, $statusCode);
44     }
45 }