Skip to content

CommandStarted and CommandFinished no longer testable in PhpUnit #46629

@henzeb

Description

@henzeb
  • Laravel Version: 10.4.1
  • PHP Version: 8.2.4
  • Database Driver & Version: -

Description:

I traced it back to this pull request which was about memory leaks, but now it does no longer dispatch the Events when running from phpunit.

That is because of the if statement around it.

if (! $this->app->runningUnitTests()) {
$this->rerouteSymfonyCommandEvents();
}

This was possible in earlier versions of Laravel, so this is definitely a breaking change.

Steps To Reproduce:

the following test will succeed in earlier versions of laravel:

public function testFailingCommandEvents()
{
      $actual = false;
      
      Event::listen(CommandStarting::class, function () use (&$actual) {
          $actual = true;
      });

      Artisan::command(
          'myApplication',
          function () {
          }
      );

      Artisan::call('myApplication');

      $this->assertTrue($actual);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions