Test Failed
Pull Request — master (#18)
by Alex
02:31
created

testImplementsParametersInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArpTest\EventDispatcher\Event;
6
7
use Arp\EventDispatcher\Event\ImmutableParameters;
8
use Arp\EventDispatcher\Event\Parameters;
9
use Arp\EventDispatcher\Event\ParametersInterface;
10
use PHPUnit\Framework\MockObject\MockObject;
11
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * @covers \Arp\EventDispatcher\Event\ImmutableParameters
15
 *
16
 * @author  Alex Patterson <[email protected]>
17
 * @package ArpTest\EventDispatcher\Event
18
 */
19
final class ImmutableParametersTest extends TestCase
20
{
21
    /**
22
     * @var ParametersInterface&MockObject
23
     */
24
    private $parameters;
25
26
    /**
27
     * Prepare the test case dependencies
28
     */
29
    public function setUp(): void
30
    {
31
        $this->parameters = $this->createMock(ParametersInterface::class);
32
    }
33
34
    /**
35
     * Assert that the class implements the ParametersInterface
36
     */
37
    public function testImplementsParametersInterface(): void
38
    {
39
        $params = new ImmutableParameters($this->parameters);
40
41
        $this->assertInstanceOf(ParametersInterface::class, $params);
42
    }
43
44
    /**
45
     * Assert that the class implements \ArrayAccess
46
     */
47
    public function testImplementsArrayAccess(): void
48
    {
49
        $params = new ImmutableParameters($this->parameters);
50
51
        $this->assertInstanceOf(\ArrayAccess::class, $params);
52
    }
53
54
    /**
55
     * Assert that parameters can be fetched via getParams() but attempts to setParams() will be ignored
56
     */
57
    public function testGetParameters(): void
58
    {
59
        $data = [
60
            'hello' => 123,
61
        ];
62
63
        $this->parameters->expects($this->exactly(2))
64
            ->method('getParams')
65
            ->willReturnOnConsecutiveCalls([], $data);
66
67
        $this->parameters->expects($this->never())->method('setParams');
68
69
        $params = new ImmutableParameters($this->parameters);
70
71
        $this->assertEmpty($params->getParams());
72
73
        // Ignore updates to set params with new data
74
        $params->setParams(
75
            [
76
                'foo' => 'bar',
77
            ]
78
        );
79
80
        $this->assertEquals($data, $params->getParams());
81
    }
82
}
83