1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace JCIT\jobqueue\tests\unit\factories; |
5
|
|
|
|
6
|
|
|
use Codeception\Test\Unit; |
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use JCIT\jobqueue\factories\JobFactory; |
9
|
|
|
use JCIT\jobqueue\jobs\HelloJob; |
10
|
|
|
|
11
|
|
|
class JobFactoryTest extends Unit |
12
|
|
|
{ |
13
|
|
|
public function testFromArrayMissingKeys(): void |
14
|
|
|
{ |
15
|
|
|
$data = []; |
16
|
|
|
$this->expectException(InvalidArgumentException::class); |
17
|
|
|
$jobFactory = new JobFactory(); |
18
|
|
|
$jobFactory->createFromArray($data); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testFromArrayUnknownClass(): void |
22
|
|
|
{ |
23
|
|
|
$data = ['class' => 'HelloJob', 'data' => []]; |
24
|
|
|
$this->expectException(InvalidArgumentException::class); |
25
|
|
|
$jobFactory = new JobFactory(); |
26
|
|
|
$jobFactory->createFromArray($data); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testFromArrayNoJob(): void |
30
|
|
|
{ |
31
|
|
|
$data = ['class' => JobFactory::class, 'data' => []]; |
32
|
|
|
$this->expectException(InvalidArgumentException::class); |
33
|
|
|
$jobFactory = new JobFactory(); |
34
|
|
|
$jobFactory->createFromArray($data); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testViaArray(): void |
38
|
|
|
{ |
39
|
|
|
$name = 'Test'; |
40
|
|
|
$job = new HelloJob($name); |
41
|
|
|
|
42
|
|
|
$jobFactory = new JobFactory(); |
43
|
|
|
$this->assertEquals($name, $jobFactory->createFromArray($jobFactory->saveToArray($job))->getName()); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testViaJson(): void |
47
|
|
|
{ |
48
|
|
|
$name = 'Test'; |
49
|
|
|
$job = new HelloJob($name); |
50
|
|
|
|
51
|
|
|
$jobFactory = new JobFactory(); |
52
|
|
|
$this->assertEquals($name, $jobFactory->createFromJson($jobFactory->saveToJson($job))->getName()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|