Skip to content

Commit fff4ef6

Browse files
committed
Add basic async test case
1 parent 9d6949c commit fff4ef6

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/AsyncTask.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function start(): void
7070
{
7171
// assume unix for now
7272
$serializedTask = $this->toBase64Serial();
73-
$this->theTask = Process::quietly()->start("php artisan async:run $serializedTask");
73+
$this->runnerProcess = Process::quietly()->start("php artisan async:run $serializedTask");
7474
}
7575

7676
/**

tests/AsyncTaskTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
class AsyncTaskTest extends BaseTestCase
88
{
9+
// directly running the runner
10+
911
public function testCanRunClosure()
1012
{
1113
// tests that our AsyncTask can run closures correctly.
@@ -39,4 +41,30 @@ public function testCanRunInterface()
3941

4042
unlink($testFileName);
4143
}
44+
45+
// ---------
46+
47+
// integration test with the cli artisan via a mocked artisan file, which tests various features of this library
48+
49+
public function testAsyncBasic()
50+
{
51+
// tests that we can dispatch async tasks to the cli artisan
52+
$testFileName = $this->getStoragePath("testAsyncBasic.txt");
53+
$message = "Hello world!";
54+
$task = new AsyncTask(function () use ($testFileName, $message) {
55+
$fp = fopen($testFileName, "w");
56+
fwrite($fp, $message);
57+
fflush($fp);
58+
fclose($fp);
59+
});
60+
$task->start();
61+
62+
// sleep a bit to wait for the async
63+
sleep(1);
64+
65+
$this->assertFileExists($testFileName);
66+
$this->assertStringEqualsFile($testFileName, $message);
67+
68+
unlink($testFileName);
69+
}
4270
}

0 commit comments

Comments
 (0)