Skip to content

Commit

Permalink
[11.x] Improve Queue::assertNothingPushed() error message (#51814)
Browse files Browse the repository at this point in the history
* improve assertNothingPushed error message

* Update QueueFake.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
SjorsO and taylorotwell authored Jun 17, 2024
1 parent ccdddaf commit 534f0d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Support/Testing/Fakes/QueueFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ public function assertCount($expectedCount)
*/
public function assertNothingPushed()
{
PHPUnit::assertEmpty($this->jobs, 'Jobs were pushed unexpectedly.');
$pushedJobs = implode("\n- ", array_keys($this->jobs));

PHPUnit::assertEmpty($this->jobs, "The following jobs were pushed unexpectedly:\n\n- $pushedJobs\n");
}

/**
Expand Down
9 changes: 8 additions & 1 deletion tests/Support/SupportTestingQueueFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use BadMethodCallException;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Application;
use Illuminate\Queue\CallQueuedClosure;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Testing\Fakes\QueueFake;
use Mockery as m;
Expand Down Expand Up @@ -194,11 +195,17 @@ public function testAssertNothingPushed()

$this->fake->push($this->job);

$this->fake->push(function () {
//
});

try {
$this->fake->assertNothingPushed();
$this->fail();
} catch (ExpectationFailedException $e) {
$this->assertStringContainsString('Jobs were pushed unexpectedly.', $e->getMessage());
$this->assertStringContainsString('The following jobs were pushed unexpectedly', $e->getMessage());
$this->assertStringContainsString(get_class($this->job), $e->getMessage());
$this->assertStringContainsString(CallQueuedClosure::class, $e->getMessage());
}
}

Expand Down

0 comments on commit 534f0d3

Please sign in to comment.