Queue::fake() not catch for artisan command #49926
Replies: 1 comment
-
I found that the reason of the failing is because the So, for make it run with queue::fake(), it's necessary to call before the So like this: <?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Queue;
use Illuminate\Foundation\Testing\WithConsoleEvents;
use App\Jobs\Job;
class JobTest extends TestCase
{
use WithConsoleEvents;
public function test_example_Queue(): void
{
Queue::fake();
$this->withoutMockingConsoleOutput();
$response = $this->artisan("app:dispatch-job");
$response->assertExitCode(0);
Queue::assertPushed(Job::class, 1);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I try to make a test on an artisan command created for myself, but it seem that the Queue::fake() not intercept the dispatch if is in inside a artisan command.
Here the minimun example:
DispatchJob.php
Job.php
And the test is this (and some variant): JobTest.php
The environment is a docker container with the following verions:
Laravel Version: 10.42.0
PHP Version: 8.3.2
I tried to use the Bus insted of Queue, but not work.
If you place the dispatch job inside a api web or directly in the test, Queue save the dispatch.
Am I missing something to setup?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions