orchestral / testbench

Laravel Testing Helper for Packages Development
https://packages.tools/testbench
MIT License
2.11k stars 136 forks source link

Artisan Facade is not mockable #411

Closed NiroDeveloper closed 3 months ago

NiroDeveloper commented 3 months ago

Description:

It is not possible to mock the Artisan Facade to test command calls.

Mockery\Exception: The class \Orchestra\Testbench\Console\Kernel is marked final and its methods cannot be replaced. Classes marked final can be passed in to \Mockery::mock() as instantiated objects to create a partial mock, but only if the mock is not subject to type hinting checks.

Is there a specific reason that this class is final, otherwise we could just remove the final keyword.

Steps To Reproduce:

  1. Write a unit test
  2. Add Artisan::shouldReceive("call")->with("backup:run")->andReturn(Command::SUCCESS)->once();
crynobone commented 3 months ago

No plan for this, you can override the Console Kernel implementations based on https://packages.tools/testbench/the-basic.html#overriding-console-kernel