ParameterBagTest::testParameterGetter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 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 ParameterBagTest extends TestCase
11
{
12
    public function testBadParameterName()
13
    {
14
        $this->expectExceptionMessage('The key must be a string');
15
16
        new Task(
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('The "erroneous" value must be a scalar or null');
30
31
        new Task(
32
            new Profile('test'),
33
            new Job\DummyJob,
34
            [
35
                'int' => 123,
36
                'string' => 'foobar',
37
                'null' => null,
38
                'bool' => true,
39
                'erroneous' => [],
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('There is no value for "foo" key');
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