Skip to content

Commit 63ede24

Browse files
committed
Test running interfaces
1 parent 83a804a commit 63ede24

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/AsyncTaskTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,19 @@ public function testCanRunClosure()
2424

2525
unlink($testFileName);
2626
}
27+
28+
public function testCanRunInterface()
29+
{
30+
// tests that our AsyncTask can run extending interfaces correctly.
31+
$testFileName = $this->getStoragePath("testClosure.txt");
32+
$message = "Hello world!";
33+
$dummyTask = new DummyAsyncTask($message, $testFileName);
34+
$task = new AsyncTask($dummyTask);
35+
$task->run();
36+
37+
$this->assertFileExists($testFileName);
38+
$this->assertStringEqualsFile($testFileName, $message);
39+
40+
unlink($testFileName);
41+
}
2742
}

tests/DummyAsyncTask.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Vectorial1024\LaravelProcessAsync\Tests;
4+
5+
use Vectorial1024\LaravelProcessAsync\AsyncTaskInterface;
6+
7+
class DummyAsyncTask implements AsyncTaskInterface
8+
{
9+
// write a message to a file
10+
11+
public function __construct(
12+
private string $message,
13+
private string $targetFilePath
14+
) {
15+
}
16+
17+
public function execute(): void
18+
{
19+
$fp = fopen($this->targetFilePath, "w");
20+
fwrite($fp, $this->message);
21+
fflush($fp);
22+
fclose($fp);
23+
}
24+
}

0 commit comments

Comments
 (0)