Skip to content
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

Auto-run queue #39

Merged
merged 1 commit into from
Oct 23, 2024
Merged

Auto-run queue #39

merged 1 commit into from
Oct 23, 2024

Conversation

markhuot
Copy link
Owner

@markhuot markhuot commented Oct 23, 2024

Auto-runs a sync queue within each test so you don't have to. That means you can mock something in a queue job and it will get run in your test automatically AFTER_SAVE or what not. E.g.,

mock(Api::class)
    ->shouldReceive('purgeUrls')
    ->once();

$entry = Entry::factory()
    ->section('authors')
    ->firstName('John')
    ->lastName('Doe')
    ->create();

The above mocks an API call that is run in a queue AFTER_SAVE. The ->create() creates the entry which triggers the Queue::push() and at the end of the test Craft::$app->queue->run() is executed, the mock is interacted with, and the test passes. If the ->create() did not trigger the queue job the mock would not be touched and the test would fail.

@markhuot markhuot merged commit 4db8d10 into main Oct 23, 2024
9 checks passed
@markhuot markhuot deleted the run-queue branch October 23, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant