Passed
Push — v2 ( 7ad8a1...1cd5a7 )
by Brice
03:05
created

TaskTest::testBadParameterName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace JobQueue\Tests\Domain\Task;
4
5
use JobQueue\Domain\Task\Profile;
6
use JobQueue\Domain\Task\Task;
7
use JobQueue\Tests\Domain\Job;
8
use PHPUnit\Framework\TestCase;
9
10
final class TaskTest extends TestCase
11
{
12
    public function testBadParameterName()
13
    {
14
        $this->expectExceptionMessage('All parameters must be named with a string key');
15
16
        $task = new Task(
0 ignored issues
show
Unused Code introduced by
The assignment to $task is dead and can be removed.
Loading history...
17
            new Profile('test'),
18
            new Job\DummyJob,
19
            [
20
                'foo' => 'bar',
21
                'bar' => 'baz',
22
                2 => 'foo',
23
            ]
24
        );
25
    }
26
27
    public function testNonScalarParameterValue()
28
    {
29
        $this->expectExceptionMessage('Parameter array must be a scalar or null');
30
31
        $task = new Task(
0 ignored issues
show
Unused Code introduced by
The assignment to $task is dead and can be removed.
Loading history...
32
            new Profile('test'),
33
            new Job\DummyJob,
34
            [
35
                'int' => 123,
36
                'string' => 'foobar',
37
                'null' => null,
38
                'bool' => true,
39
                'array' => [],
40
            ]
41
        );
42
    }
43
44
    public function testParameterGetter()
45
    {
46
        $task = new Task(
47
            new Profile('test'),
48
            new Job\DummyJob,
49
            [
50
                'foo' => 'bar',
51
                'bar' => 'baz',
52
            ]
53
        );
54
55
        $this->assertTrue($task->hasParameter('foo'));
56
    }
57
58
    public function testNonExistentParameterGetter()
59
    {
60
        $this->expectExceptionMessage('Parameter "foo" does not exists');
61
62
        $task = new Task(
63
            new Profile('test'),
64
            new Job\DummyJob,
65
            [
66
                'bar' => 'baz',
67
            ]
68
        );
69
70
        $task->getParameter('foo');
71
    }
72
73
    public function testSerialization()
74
    {
75
        $task = new Task(
76
            new Profile('test'),
77
            new Job\DummyJob
78
        );
79
80
        $serializedTask = serialize($task);
81
        $this->assertTrue(is_string($serializedTask));
82
83
        $unserializedTask = unserialize($serializedTask);
84
        $this->assertInstanceOf(Task::class, $unserializedTask);
85
86
        $jsonSerializedTask = json_encode($unserializedTask);
87
        $this->assertTrue(is_string($jsonSerializedTask));
88
    }
89
90
    public function testHumanReadableJobName()
91
    {
92
        $task = new Task(
93
            new Profile('test'),
94
            new Job\DummyJob
95
        );
96
        $this->assertEquals('dummy', $task->getJobName(true));
97
98
        $complexNameJob = new Task(
99
            new Profile('test'),
100
            new Job\ComplexTOSnakeCASEJob
101
        );
102
        $this->assertEquals('complex_to_snake_case', $complexNameJob->getJobName(true));
103
    }
104
}
105