Skip to content

Commit 83a804a

Browse files
committed
Test running closures
1 parent 25fe227 commit 83a804a

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

storage/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/AsyncTaskTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,26 @@
22

33
namespace Vectorial1024\LaravelProcessAsync\Tests;
44

5+
use Vectorial1024\LaravelProcessAsync\AsyncTask;
6+
57
class AsyncTaskTest extends BaseTestCase
68
{
7-
// nothing for now
9+
public function testCanRunClosure()
10+
{
11+
// tests that our AsyncTask can run closures correctly.
12+
$testFileName = $this->getStoragePath("testClosure.txt");
13+
$message = "Hello world!";
14+
$task = new AsyncTask(function () use ($testFileName, $message) {
15+
$fp = fopen($testFileName, "w");
16+
fwrite($fp, $message);
17+
fflush($fp);
18+
fclose($fp);
19+
});
20+
$task->run();
21+
22+
$this->assertFileExists($testFileName);
23+
$this->assertStringEqualsFile($testFileName, $message);
24+
25+
unlink($testFileName);
26+
}
827
}

tests/BaseTestCase.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ protected function getPackageProviders($app)
2020

2121
// ---
2222

23+
/**
24+
* Returns the path for mocking the Laravel storage path.
25+
* @param string $fileName
26+
* @return string
27+
*/
28+
protected function getStoragePath(string $fileName): string
29+
{
30+
return dirname(__FILE__, 2) . "/storage/$fileName";
31+
}
32+
33+
// ---
34+
2335
public function call($method, $uri, $parameters = [], $files = [], $server = [], $content = null, $changeHistory = true)
2436
{
2537
// pass

0 commit comments

Comments
 (0)