Skip to content

[Console] Testing commands with mocked dependencies fails since 3.0.3 #18558

Closed
@ruudvanderweijde

Description

@ruudvanderweijde

In symfony 3.0.2 and before you could test a console command with mocks like:

$application = new Application($kernel);
$application->add(new MyConsoleCommand($myMockedRepository));

// we check it's properly registered :)
$command = $application->find('namespace:my-command');

$commandTester = new CommandTester($command);
// execute command

But since 3.0.3 the mocked object is not set in the console command when it is executed.
A way to work around it is:

$myCommand = new MyConsoleCommand($myMockedRepository);
$application = new Application($kernel);
$application->add($myCommand);

$commandTester = new CommandTester($command);
// execute command

But then I cannot use the $application->find() method.

Was this a desired change? I cannot seem to find it in the change log.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions