1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107:
<?php
namespace Symfony\Component\Console\Tests\Descriptor;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\BufferedOutput;
abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase
{
public function testDescribeInputArgument(InputArgument $argument, $expectedDescription)
{
$this->assertDescription($expectedDescription, $argument);
}
public function testDescribeInputOption(InputOption $option, $expectedDescription)
{
$this->assertDescription($expectedDescription, $option);
}
public function testDescribeInputDefinition(InputDefinition $definition, $expectedDescription)
{
$this->assertDescription($expectedDescription, $definition);
}
public function testDescribeCommand(Command $command, $expectedDescription)
{
$this->assertDescription($expectedDescription, $command);
}
public function testDescribeApplication(Application $application, $expectedDescription)
{
foreach ($application->all() as $command) {
$command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp()));
}
$this->assertDescription($expectedDescription, $application);
}
public function getDescribeInputArgumentTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getInputArguments());
}
public function getDescribeInputOptionTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getInputOptions());
}
public function getDescribeInputDefinitionTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getInputDefinitions());
}
public function getDescribeCommandTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getCommands());
}
public function getDescribeApplicationTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getApplications());
}
abstract protected function getDescriptor();
abstract protected function getFormat();
private function getDescriptionTestData(array $objects)
{
$data = array();
foreach ($objects as $name => $object) {
$description = file_get_contents(sprintf('%s/../Fixtures/%s.%s', __DIR__, $name, $this->getFormat()));
$data[] = array($object, $description);
}
return $data;
}
protected function assertDescription($expectedDescription, $describedObject)
{
$output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
$this->getDescriptor()->describe($output, $describedObject, array('raw_output' => true));
$this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL, "\n", $output->fetch())));
}
}