TYPO3  7.6
AbstractDescriptorTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Console\Tests\Descriptor;
13 
20 
21 abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase
22 {
24  public function testDescribeInputArgument(InputArgument $argument, $expectedDescription)
25  {
26  $this->assertDescription($expectedDescription, $argument);
27  }
28 
30  public function testDescribeInputOption(InputOption $option, $expectedDescription)
31  {
32  $this->assertDescription($expectedDescription, $option);
33  }
34 
36  public function testDescribeInputDefinition(InputDefinition $definition, $expectedDescription)
37  {
38  $this->assertDescription($expectedDescription, $definition);
39  }
40 
42  public function testDescribeCommand(Command $command, $expectedDescription)
43  {
44  $this->assertDescription($expectedDescription, $command);
45  }
46 
48  public function testDescribeApplication(Application $application, $expectedDescription)
49  {
50  // Replaces the dynamic placeholders of the command help text with a static version.
51  // The placeholder %command.full_name% includes the script path that is not predictable
52  // and can not be tested against.
53  foreach ($application->all() as $command) {
54  $command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp()));
55  }
56 
57  $this->assertDescription($expectedDescription, $application);
58  }
59 
61  {
63  }
64 
66  {
68  }
69 
71  {
73  }
74 
75  public function getDescribeCommandTestData()
76  {
78  }
79 
81  {
83  }
84 
85  abstract protected function getDescriptor();
86  abstract protected function getFormat();
87 
88  private function getDescriptionTestData(array $objects)
89  {
90  $data = array();
91  foreach ($objects as $name => $object) {
92  $description = file_get_contents(sprintf('%s/../Fixtures/%s.%s', __DIR__, $name, $this->getFormat()));
93  $data[] = array($object, $description);
94  }
95 
96  return $data;
97  }
98 
99  protected function assertDescription($expectedDescription, $describedObject)
100  {
102  $this->getDescriptor()->describe($output, $describedObject, array('raw_output' => true));
103  $this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL, "\n", $output->fetch())));
104  }
105 }