Skip to content

[12.x] Add the assertClosureNotPushed method #10648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -2488,9 +2488,12 @@ test('orders can be shipped', function () {
// Assert a job was not pushed...
Queue::assertNotPushed(AnotherJob::class);

// Assert that a Closure was pushed to the queue...
// Assert that a closure was pushed to the queue...
Queue::assertClosurePushed();

// Assert that a closure was not pushed...
Queue::assertClosureNotPushed();

// Assert the total number of jobs that were pushed...
Queue::assertCount(3);
});
Expand Down Expand Up @@ -2527,21 +2530,30 @@ class ExampleTest extends TestCase
// Assert a job was not pushed...
Queue::assertNotPushed(AnotherJob::class);

// Assert that a Closure was pushed to the queue...
// Assert that a closure was pushed to the queue...
Queue::assertClosurePushed();

// Assert that a closure was not pushed...
Queue::assertClosureNotPushed();

// Assert the total number of jobs that were pushed...
Queue::assertCount(3);
}
}
```

You may pass a closure to the `assertPushed` or `assertNotPushed` methods in order to assert that a job was pushed that passes a given "truth test". If at least one job was pushed that passes the given truth test then the assertion will be successful:
You may pass a closure to the `assertPushed`, `assertNotPushed`, `assertClosurePushed`, or `assertClosureNotPushed` methods in order to assert that a job was pushed that passes a given "truth test". If at least one job was pushed that passes the given truth test then the assertion will be successful:

```php
use Illuminate\Queue\CallQueuedClosure;

Queue::assertPushed(function (ShipOrder $job) use ($order) {
return $job->order->id === $order->id;
});

Queue::assertClosurePushed(function (CallQueuedClosure $job) {
return $job->name === 'validate-order';
});
```

<a name="faking-a-subset-of-jobs"></a>
Expand Down