Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle] Change priority of AddConsoleCommandPass to TYPE_BEFORE_REMOVING #27272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function build(ContainerBuilder $container)
$this->addCompilerPassIfExists($container, AddConstraintValidatorsPass::class, PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_AFTER_REMOVING, -255);
$this->addCompilerPassIfExists($container, AddValidatorInitializersPass::class);
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class);
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class, PassConfig::TYPE_BEFORE_REMOVING);
if (class_exists(TranslatorPass::class)) {
// Arguments to be removed in 4.0, relying on the default values
$container->addCompilerPass(new TranslatorPass('translator.default', 'translation.loader'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
namespace Symfony\Component\Console\Tests\DependencyInjection;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\TypedReference;
Expand All @@ -28,7 +30,7 @@ class AddConsoleCommandPassTest extends TestCase
public function testProcess($public)
{
$container = new ContainerBuilder();
$container->addCompilerPass(new AddConsoleCommandPass());
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->setParameter('my-command.class', 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand');

$definition = new Definition('%my-command.class%');
Expand Down Expand Up @@ -127,7 +129,7 @@ public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->addCompilerPass(new AddConsoleCommandPass());
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);

$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
$definition->addTag('console.command');
Expand All @@ -145,7 +147,7 @@ public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->addCompilerPass(new AddConsoleCommandPass());
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);

$definition = new Definition('SplObjectStorage');
$definition->addTag('console.command');
Expand Down Expand Up @@ -175,6 +177,79 @@ public function testProcessPrivateServicesWithSameCommand()
$this->assertTrue($container->hasAlias($alias1));
$this->assertTrue($container->hasAlias($alias2));
}

public function testProcessOnChildDefinitionWithClass()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
$className = 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand';

$parentId = 'my-parent-command';
$childId = 'my-child-command';

$parentDefinition = new Definition(/* no class */);
$parentDefinition->setAbstract(true)->setPublic(false);

$childDefinition = new ChildDefinition($parentId);
$childDefinition->addTag('console.command')->setPublic(true);
$childDefinition->setClass($className);

$container->setDefinition($parentId, $parentDefinition);
$container->setDefinition($childId, $childDefinition);

$container->compile();
$command = $container->get($childId);

$this->assertInstanceOf($className, $command);
}

public function testProcessOnChildDefinitionWithParentClass()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
$className = 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand';

$parentId = 'my-parent-command';
$childId = 'my-child-command';

$parentDefinition = new Definition($className);
$parentDefinition->setAbstract(true)->setPublic(false);

$childDefinition = new ChildDefinition($parentId);
$childDefinition->addTag('console.command')->setPublic(true);

$container->setDefinition($parentId, $parentDefinition);
$container->setDefinition($childId, $childDefinition);

$container->compile();
$command = $container->get($childId);

$this->assertInstanceOf($className, $command);
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage The definition for "my-child-command" has no class.
*/
public function testProcessOnChildDefinitionWithoutClass()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);

$parentId = 'my-parent-command';
$childId = 'my-child-command';

$parentDefinition = new Definition();
$parentDefinition->setAbstract(true)->setPublic(false);

$childDefinition = new ChildDefinition($parentId);
$childDefinition->addTag('console.command')->setPublic(true);

$container->setDefinition($parentId, $parentDefinition);
$container->setDefinition($childId, $childDefinition);

$container->compile();
}
}

class MyCommand extends Command
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.