JobFactoryTest::testFromArrayNoJob()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 1
b 0
f 1
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());
0 ignored issues
show
Bug introduced by
The method getName() does not exist on JCIT\jobqueue\interfaces\JobInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to JCIT\jobqueue\interfaces\JobInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        $this->assertEquals($name, $jobFactory->createFromArray($jobFactory->saveToArray($job))->/** @scrutinizer ignore-call */ getName());
Loading history...
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