N°2651 Remove lib test files from index

This commit is contained in:
Pierre Goiffon
2019-12-20 11:55:55 +01:00
parent 4766ca3fd0
commit c75e6960a7
1896 changed files with 5 additions and 134443 deletions

View File

@@ -1,261 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Console;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpKernel\KernelInterface;
class ApplicationTest extends TestCase
{
public function testBundleInterfaceImplementation()
{
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
$kernel = $this->getKernel([$bundle], true);
$application = new Application($kernel);
$application->doRun(new ArrayInput(['list']), new NullOutput());
}
public function testBundleCommandsAreRegistered()
{
$bundle = $this->createBundleMock([]);
$kernel = $this->getKernel([$bundle], true);
$application = new Application($kernel);
$application->doRun(new ArrayInput(['list']), new NullOutput());
// Calling twice: registration should only be done once.
$application->doRun(new ArrayInput(['list']), new NullOutput());
}
public function testBundleCommandsAreRetrievable()
{
$bundle = $this->createBundleMock([]);
$kernel = $this->getKernel([$bundle]);
$application = new Application($kernel);
$application->all();
// Calling twice: registration should only be done once.
$application->all();
}
public function testBundleSingleCommandIsRetrievable()
{
$command = new Command('example');
$bundle = $this->createBundleMock([$command]);
$kernel = $this->getKernel([$bundle]);
$application = new Application($kernel);
$this->assertSame($command, $application->get('example'));
}
public function testBundleCommandCanBeFound()
{
$command = new Command('example');
$bundle = $this->createBundleMock([$command]);
$kernel = $this->getKernel([$bundle]);
$application = new Application($kernel);
$this->assertSame($command, $application->find('example'));
}
public function testBundleCommandCanBeFoundByAlias()
{
$command = new Command('example');
$command->setAliases(['alias']);
$bundle = $this->createBundleMock([$command]);
$kernel = $this->getKernel([$bundle]);
$application = new Application($kernel);
$this->assertSame($command, $application->find('alias'));
}
public function testBundleCommandsHaveRightContainer()
{
$command = $this->getMockForAbstractClass('Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand', ['foo'], '', true, true, true, ['setContainer']);
$command->setCode(function () {});
$command->expects($this->exactly(2))->method('setContainer');
$application = new Application($this->getKernel([], true));
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->add($command);
$tester = new ApplicationTester($application);
// set container is called here
$tester->run(['command' => 'foo']);
// as the container might have change between two runs, setContainer must called again
$tester->run(['command' => 'foo']);
}
public function testBundleCommandCanOverriddeAPreExistingCommandWithTheSameName()
{
$command = new Command('example');
$bundle = $this->createBundleMock([$command]);
$kernel = $this->getKernel([$bundle]);
$application = new Application($kernel);
$newCommand = new Command('example');
$application->add($newCommand);
$this->assertSame($newCommand, $application->get('example'));
}
public function testRunOnlyWarnsOnUnregistrableCommand()
{
$container = new ContainerBuilder();
$container->register('event_dispatcher', EventDispatcher::class);
$container->register(ThrowingCommand::class, ThrowingCommand::class);
$container->setParameter('console.command.ids', [ThrowingCommand::class => ThrowingCommand::class]);
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel
->method('getBundles')
->willReturn([$this->createBundleMock(
[(new Command('fine'))->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('fine'); })]
)]);
$kernel
->method('getContainer')
->willReturn($container);
$application = new Application($kernel);
$application->setAutoExit(false);
$tester = new ApplicationTester($application);
$tester->run(['command' => 'fine']);
$output = $tester->getDisplay();
$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Some commands could not be registered:', $output);
$this->assertStringContainsString('throwing', $output);
$this->assertStringContainsString('fine', $output);
}
public function testRegistrationErrorsAreDisplayedOnCommandNotFound()
{
$container = new ContainerBuilder();
$container->register('event_dispatcher', EventDispatcher::class);
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel
->method('getBundles')
->willReturn([$this->createBundleMock(
[(new Command(null))->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('fine'); })]
)]);
$kernel
->method('getContainer')
->willReturn($container);
$application = new Application($kernel);
$application->setAutoExit(false);
$tester = new ApplicationTester($application);
$tester->run(['command' => 'fine']);
$output = $tester->getDisplay();
$this->assertSame(1, $tester->getStatusCode());
$this->assertStringContainsString('Some commands could not be registered:', $output);
$this->assertStringContainsString('Command "fine" is not defined.', $output);
}
private function getKernel(array $bundles, $useDispatcher = false)
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
if ($useDispatcher) {
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$dispatcher
->expects($this->atLeastOnce())
->method('dispatch')
;
$container
->expects($this->atLeastOnce())
->method('get')
->with($this->equalTo('event_dispatcher'))
->willReturn($dispatcher);
}
$container
->expects($this->exactly(2))
->method('hasParameter')
->withConsecutive(['console.command.ids'], ['console.lazy_command.ids'])
->willReturnOnConsecutiveCalls(true, true)
;
$container
->expects($this->exactly(2))
->method('getParameter')
->withConsecutive(['console.lazy_command.ids'], ['console.command.ids'])
->willReturnOnConsecutiveCalls([], [])
;
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
$kernel
->expects($this->any())
->method('getBundles')
->willReturn($bundles)
;
$kernel
->expects($this->any())
->method('getContainer')
->willReturn($container)
;
return $kernel;
}
private function createBundleMock(array $commands)
{
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
$bundle
->expects($this->once())
->method('registerCommands')
->willReturnCallback(function (Application $application) use ($commands) {
$application->addCommands($commands);
})
;
return $bundle;
}
}
class ThrowingCommand extends Command
{
public function __construct()
{
throw new \Exception('throwing');
}
}

View File

@@ -1,252 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
abstract class AbstractDescriptorTest extends TestCase
{
/** @dataProvider getDescribeRouteCollectionTestData */
public function testDescribeRouteCollection(RouteCollection $routes, $expectedDescription)
{
$this->assertDescription($expectedDescription, $routes);
}
public function getDescribeRouteCollectionTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getRouteCollections());
}
/** @dataProvider getDescribeRouteTestData */
public function testDescribeRoute(Route $route, $expectedDescription)
{
$this->assertDescription($expectedDescription, $route);
}
public function getDescribeRouteTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getRoutes());
}
/** @dataProvider getDescribeContainerParametersTestData */
public function testDescribeContainerParameters(ParameterBag $parameters, $expectedDescription)
{
$this->assertDescription($expectedDescription, $parameters);
}
public function getDescribeContainerParametersTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getContainerParameters());
}
/** @dataProvider getDescribeContainerBuilderTestData */
public function testDescribeContainerBuilder(ContainerBuilder $builder, $expectedDescription, array $options)
{
$this->assertDescription($expectedDescription, $builder, $options);
}
public function getDescribeContainerBuilderTestData()
{
return $this->getContainerBuilderDescriptionTestData(ObjectsProvider::getContainerBuilders());
}
/** @dataProvider getDescribeContainerDefinitionTestData */
public function testDescribeContainerDefinition(Definition $definition, $expectedDescription)
{
$this->assertDescription($expectedDescription, $definition);
}
public function getDescribeContainerDefinitionTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getContainerDefinitions());
}
/** @dataProvider getDescribeContainerDefinitionWithArgumentsShownTestData */
public function testDescribeContainerDefinitionWithArgumentsShown(Definition $definition, $expectedDescription)
{
$this->assertDescription($expectedDescription, $definition, ['show_arguments' => true]);
}
public function getDescribeContainerDefinitionWithArgumentsShownTestData()
{
$definitions = ObjectsProvider::getContainerDefinitions();
$definitionsWithArgs = [];
foreach ($definitions as $key => $definition) {
$definitionsWithArgs[str_replace('definition_', 'definition_arguments_', $key)] = $definition;
}
return $this->getDescriptionTestData($definitionsWithArgs);
}
/** @dataProvider getDescribeContainerAliasTestData */
public function testDescribeContainerAlias(Alias $alias, $expectedDescription)
{
$this->assertDescription($expectedDescription, $alias);
}
public function getDescribeContainerAliasTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getContainerAliases());
}
/** @dataProvider getDescribeContainerDefinitionWhichIsAnAliasTestData */
public function testDescribeContainerDefinitionWhichIsAnAlias(Alias $alias, $expectedDescription, ContainerBuilder $builder, $options = [])
{
$this->assertDescription($expectedDescription, $builder, $options);
}
public function getDescribeContainerDefinitionWhichIsAnAliasTestData()
{
$builder = current(ObjectsProvider::getContainerBuilders());
$builder->setDefinition('service_1', $builder->getDefinition('definition_1'));
$builder->setDefinition('service_2', $builder->getDefinition('definition_2'));
$aliases = ObjectsProvider::getContainerAliases();
$aliasesWithDefinitions = [];
foreach ($aliases as $name => $alias) {
$aliasesWithDefinitions[str_replace('alias_', 'alias_with_definition_', $name)] = $alias;
}
$i = 0;
$data = $this->getDescriptionTestData($aliasesWithDefinitions);
foreach ($aliases as $name => $alias) {
$data[$i][] = $builder;
$data[$i][] = ['id' => $name];
++$i;
}
return $data;
}
/** @dataProvider getDescribeContainerParameterTestData */
public function testDescribeContainerParameter($parameter, $expectedDescription, array $options)
{
$this->assertDescription($expectedDescription, $parameter, $options);
}
public function getDescribeContainerParameterTestData()
{
$data = $this->getDescriptionTestData(ObjectsProvider::getContainerParameter());
$data[0][] = ['parameter' => 'database_name'];
$data[1][] = ['parameter' => 'twig.form.resources'];
return $data;
}
/** @dataProvider getDescribeEventDispatcherTestData */
public function testDescribeEventDispatcher(EventDispatcher $eventDispatcher, $expectedDescription, array $options)
{
$this->assertDescription($expectedDescription, $eventDispatcher, $options);
}
public function getDescribeEventDispatcherTestData()
{
return $this->getEventDispatcherDescriptionTestData(ObjectsProvider::getEventDispatchers());
}
/** @dataProvider getDescribeCallableTestData */
public function testDescribeCallable($callable, $expectedDescription)
{
$this->assertDescription($expectedDescription, $callable);
}
public function getDescribeCallableTestData()
{
return $this->getDescriptionTestData(ObjectsProvider::getCallables());
}
abstract protected function getDescriptor();
abstract protected function getFormat();
private function assertDescription($expectedDescription, $describedObject, array $options = [])
{
$options['is_debug'] = false;
$options['raw_output'] = true;
$options['raw_text'] = true;
$output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
if ('txt' === $this->getFormat()) {
$options['output'] = new SymfonyStyle(new ArrayInput([]), $output);
}
$this->getDescriptor()->describe($output, $describedObject, $options);
if ('json' === $this->getFormat()) {
$this->assertEquals(json_encode(json_decode($expectedDescription), JSON_PRETTY_PRINT), json_encode(json_decode($output->fetch()), JSON_PRETTY_PRINT));
} else {
$this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL, "\n", $output->fetch())));
}
}
private function getDescriptionTestData(array $objects)
{
$data = [];
foreach ($objects as $name => $object) {
$description = file_get_contents(sprintf('%s/../../Fixtures/Descriptor/%s.%s', __DIR__, $name, $this->getFormat()));
$data[] = [$object, $description];
}
return $data;
}
private function getContainerBuilderDescriptionTestData(array $objects)
{
$variations = [
'services' => ['show_private' => true],
'public' => ['show_private' => false],
'tag1' => ['show_private' => true, 'tag' => 'tag1'],
'tags' => ['group_by' => 'tags', 'show_private' => true],
'arguments' => ['show_private' => false, 'show_arguments' => true],
];
$data = [];
foreach ($objects as $name => $object) {
foreach ($variations as $suffix => $options) {
$description = file_get_contents(sprintf('%s/../../Fixtures/Descriptor/%s_%s.%s', __DIR__, $name, $suffix, $this->getFormat()));
$data[] = [$object, $description, $options];
}
}
return $data;
}
private function getEventDispatcherDescriptionTestData(array $objects)
{
$variations = [
'events' => [],
'event1' => ['event' => 'event1'],
];
$data = [];
foreach ($objects as $name => $object) {
foreach ($variations as $suffix => $options) {
$description = file_get_contents(sprintf('%s/../../Fixtures/Descriptor/%s_%s.%s', __DIR__, $name, $suffix, $this->getFormat()));
$data[] = [$object, $description, $options];
}
}
return $data;
}
}

View File

@@ -1,27 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\JsonDescriptor;
class JsonDescriptorTest extends AbstractDescriptorTest
{
protected function getDescriptor()
{
return new JsonDescriptor();
}
protected function getFormat()
{
return 'json';
}
}

View File

@@ -1,27 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\MarkdownDescriptor;
class MarkdownDescriptorTest extends AbstractDescriptorTest
{
protected function getDescriptor()
{
return new MarkdownDescriptor();
}
protected function getFormat()
{
return 'md';
}
}

View File

@@ -1,204 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Routing\CompiledRoute;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class ObjectsProvider
{
public static function getRouteCollections()
{
$collection1 = new RouteCollection();
foreach (self::getRoutes() as $name => $route) {
$collection1->add($name, $route);
}
return ['route_collection_1' => $collection1];
}
public static function getRoutes()
{
return [
'route_1' => new RouteStub(
'/hello/{name}',
['name' => 'Joseph'],
['name' => '[a-z]+'],
['opt1' => 'val1', 'opt2' => 'val2'],
'localhost',
['http', 'https'],
['get', 'head']
),
'route_2' => new RouteStub(
'/name/add',
[],
[],
['opt1' => 'val1', 'opt2' => 'val2'],
'localhost',
['http', 'https'],
['put', 'post']
),
];
}
public static function getContainerParameters()
{
return [
'parameters_1' => new ParameterBag([
'integer' => 12,
'string' => 'Hello world!',
'boolean' => true,
'array' => [12, 'Hello world!', true],
]),
];
}
public static function getContainerParameter()
{
$builder = new ContainerBuilder();
$builder->setParameter('database_name', 'symfony');
$builder->setParameter('twig.form.resources', [
'bootstrap_3_horizontal_layout.html.twig',
'bootstrap_3_layout.html.twig',
'form_div_layout.html.twig',
'form_table_layout.html.twig',
]);
return [
'parameter' => $builder,
'array_parameter' => $builder,
];
}
public static function getContainerBuilders()
{
$builder1 = new ContainerBuilder();
$builder1->setDefinitions(self::getContainerDefinitions());
$builder1->setAliases(self::getContainerAliases());
return ['builder_1' => $builder1];
}
public static function getContainerDefinitions()
{
$definition1 = new Definition('Full\\Qualified\\Class1');
$definition2 = new Definition('Full\\Qualified\\Class2');
return [
'definition_1' => $definition1
->setPublic(true)
->setSynthetic(false)
->setLazy(true)
->setAbstract(true)
->addArgument(new Reference('definition2'))
->addArgument('%parameter%')
->addArgument(new Definition('inline_service', ['arg1', 'arg2']))
->addArgument([
'foo',
new Reference('definition2'),
new Definition('inline_service'),
])
->addArgument(new IteratorArgument([
new Reference('definition_1'),
new Reference('definition_2'),
]))
->setFactory(['Full\\Qualified\\FactoryClass', 'get']),
'definition_2' => $definition2
->setPublic(false)
->setSynthetic(true)
->setFile('/path/to/file')
->setLazy(false)
->setAbstract(false)
->addTag('tag1', ['attr1' => 'val1', 'attr2' => 'val2'])
->addTag('tag1', ['attr3' => 'val3'])
->addTag('tag2')
->addMethodCall('setMailer', [new Reference('mailer')])
->setFactory([new Reference('factory.service'), 'get']),
];
}
public static function getContainerAliases()
{
return [
'alias_1' => new Alias('service_1', true),
'alias_2' => new Alias('service_2', false),
];
}
public static function getEventDispatchers()
{
$eventDispatcher = new EventDispatcher();
$eventDispatcher->addListener('event1', 'global_function', 255);
$eventDispatcher->addListener('event1', function () { return 'Closure'; }, -1);
$eventDispatcher->addListener('event2', new CallableClass());
return ['event_dispatcher_1' => $eventDispatcher];
}
public static function getCallables()
{
$callables = [
'callable_1' => 'array_key_exists',
'callable_2' => ['Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass', 'staticMethod'],
'callable_3' => [new CallableClass(), 'method'],
'callable_4' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass::staticMethod',
'callable_5' => ['Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\ExtendedCallableClass', 'parent::staticMethod'],
'callable_6' => function () { return 'Closure'; },
'callable_7' => new CallableClass(),
];
if (\PHP_VERSION_ID >= 70100) {
$callables['callable_from_callable'] = \Closure::fromCallable(new CallableClass());
}
return $callables;
}
}
class CallableClass
{
public function __invoke()
{
}
public static function staticMethod()
{
}
public function method()
{
}
}
class ExtendedCallableClass extends CallableClass
{
public static function staticMethod()
{
}
}
class RouteStub extends Route
{
public function compile()
{
return new CompiledRoute('', '#PATH_REGEX#', [], [], '#HOST_REGEX#');
}
}

View File

@@ -1,37 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\TextDescriptor;
class TextDescriptorTest extends AbstractDescriptorTest
{
protected function setUp()
{
putenv('COLUMNS=121');
}
protected function tearDown()
{
putenv('COLUMNS');
}
protected function getDescriptor()
{
return new TextDescriptor();
}
protected function getFormat()
{
return 'txt';
}
}

View File

@@ -1,27 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\XmlDescriptor;
class XmlDescriptorTest extends AbstractDescriptorTest
{
protected function getDescriptor()
{
return new XmlDescriptor();
}
protected function getFormat()
{
return 'xml';
}
}