Skip to content

Provide documentation for the fake objects #22

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 1 commit into from
May 7, 2025
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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,36 @@ You may need to clear your Laravel optimisation cache after changing this value.

The contents of the async tasks will be signed by this secret key, so that this library can know whether the tasks are started by this library itself or someone else.

### Fake Objects
Fake objects are available for users to simulate async task behaviors without actually starting async tasks. This should be helpful when writing tests that attempts to react to task statuses.

The following fake objects are available:

- `FakeAsyncTask`: a fake of `AsyncTask`
- `FakeAsyncTaskStatus`: a fake of `AsyncTaskStatus`

Notably, they can be used like this:

```php
// you may obtain the task status in the usual way...
$fakeTask = new FakeAsyncTask(/* ... */, taskID: "TestingTask");
$fakeStatus = $fakeTask->start();

// ...or just construct it directly
$fakeStatusDirect = new FakeAsyncTaskStatus("TestingTask");
// both are the same
assert($fakeStatus == $fakeStatusDirect); // passes

// in your test code, fake task status can be used just like the normal task status:
$fakeStatus->isRunning(); // default returns true

// note: FakeAsyncTaskStatus defaults to "is running" when constructed
// to simulate "task ended", simply do:
$fakeStatus->fakeStopRunning();
// then, the following will return false
$fakeStatus->isRunning(); // returns false
```

## Testing
PHPUnit via Composer script:
```sh
Expand Down