File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments