From abe07a9f166564157c83cfea9bae0607d40e7983 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Wed, 23 Oct 2024 17:53:55 -0400 Subject: [PATCH 1/2] Create queue.md Docs --- docs/queue.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 docs/queue.md diff --git a/docs/queue.md b/docs/queue.md new file mode 100644 index 0000000..543f6cb --- /dev/null +++ b/docs/queue.md @@ -0,0 +1,12 @@ +# Queue Jobs + +Any `Sync` queue jobs are automatically run at the end of each test. Essentially thr equivilant of, + +```php +it('runs queues', function() { + Entry::factory()->create(); + + // This is run implicitely for you + Craft::$app->queue->run(); +}); +``` From 7d7f5f73f279f19ed066702b5ae6e49b784a65dc Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Thu, 24 Oct 2024 17:49:21 -0400 Subject: [PATCH 2/2] Update queue.md --- docs/queue.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/queue.md b/docs/queue.md index 543f6cb..2760d6f 100644 --- a/docs/queue.md +++ b/docs/queue.md @@ -1,12 +1,19 @@ # Queue Jobs -Any `Sync` queue jobs are automatically run at the end of each test. Essentially thr equivilant of, +Any `Sync` queue jobs are automatically run at the end of each test. Essentially the equivilant of, ```php it('runs queues', function() { + mock(UpdateSearchIndex::class) + ->shouldReceive('execute') + ->once(); + + // Act and perform your test Entry::factory()->create(); - // This is run implicitely for you - Craft::$app->queue->run(); + // This is run implicitely for you, as the very last step + // Craft::$app->queue->run(); }); ``` + +This test confirms that when an entry is created the `UpdateSearchIndex` job is run. You could just as easily test that a custom action or custom listener is run when an entry matching certain conditions is run.