Skip to content

Commit 6aca9ae

Browse files
committed
Test the runner itself
1 parent 63ede24 commit 6aca9ae

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/AsyncTaskRunnerTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Vectorial1024\LaravelProcessAsync\Tests;
4+
5+
use Artisan;
6+
use Exception;
7+
use stdClass;
8+
use Vectorial1024\LaravelProcessAsync\AsyncTask;
9+
use Vectorial1024\LaravelProcessAsync\AsyncTaskRunnerCommand;
10+
11+
class AsyncTaskRunnerTest extends BaseTestCase
12+
{
13+
public function testNakedCommand()
14+
{
15+
// tests that it can cancel itself when it is run with nothing
16+
// there should be an exception from Symfony since we did not provide the required argument
17+
$this->expectException(Exception::class);
18+
Artisan::call(AsyncTaskRunnerCommand::class);
19+
}
20+
21+
public function testInvalidSerialCommand()
22+
{
23+
// tests that it can cancel itself when it receives strange serialized code
24+
$statusCode = Artisan::call(AsyncTaskRunnerCommand::class, [
25+
'task' => "Hello World!",
26+
]);
27+
$this->assertNotEquals(0, $statusCode);
28+
}
29+
30+
public function testWrongTypeCommand()
31+
{
32+
// tests that it can cancel itself when it receives a valid PHP object, but is not the type it wants
33+
$badObject = new stdClass();
34+
$badObject->name = 'apple';
35+
$statusCode = Artisan::call(AsyncTaskRunnerCommand::class, [
36+
'task' => base64_encode(serialize($badObject)),
37+
]);
38+
$this->assertNotEquals(0, $statusCode);
39+
}
40+
41+
public function testValidCommand()
42+
{
43+
// tests that there are no exceptions when the given task is valid and throws no exceptions
44+
$nop = function () {
45+
// pass
46+
return;
47+
};
48+
$task = new AsyncTask($nop);
49+
$statusCode = Artisan::call(AsyncTaskRunnerCommand::class, [
50+
'task' => $task->toBase64Serial(),
51+
]);
52+
$this->assertEquals(0, $statusCode);
53+
}
54+
}

0 commit comments

Comments
 (0)