Skip to content

Commit c5e5ce7

Browse files
committed
Describe the fake objects
1 parent abf82ad commit c5e5ce7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,36 @@ You may need to clear your Laravel optimisation cache after changing this value.
129129

130130
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.
131131

132+
### Fake Objects
133+
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.
134+
135+
The following fake objects are available:
136+
137+
- `FakeAsyncTask`: a fake of `AsyncTask`
138+
- `FakeAsyncTaskStatus`: a fake of `AsyncTaskStatus`
139+
140+
Notably, they can be used like this:
141+
142+
```php
143+
// you may obtain the task status in the usual way...
144+
$fakeTask = new FakeAsyncTask(/* ... */, taskID: "TestingTask");
145+
$fakeStatus = $fakeTask->start();
146+
147+
// ...or just construct it directly
148+
$fakeStatusDirect = new FakeAsyncTaskStatus("TestingTask");
149+
// both are the same
150+
assert($fakeStatus == $fakeStatusDirect); // passes
151+
152+
// in your test code, fake task status can be used just like the normal task status:
153+
$fakeStatus->isRunning(); // default returns true
154+
155+
// note: FakeAsyncTaskStatus defaults to "is running" when constructed
156+
// to simulate "task ended", simply do:
157+
$fakeStatus->fakeStopRunning();
158+
// then, the following will return false
159+
$fakeStatus->isRunning(); // returns false
160+
```
161+
132162
## Testing
133163
PHPUnit via Composer script:
134164
```sh

0 commit comments

Comments
 (0)