Passed
Pull Request — master (#25)
by Mathieu
04:23 queued 01:40
created

ContainerTest::testContainerWarehouse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
use Suricate\Container;
4
5
class ContainerTest extends \PHPUnit\Framework\TestCase
6
{
7
    public function testContainerExists()
8
    {
9
        $testContainer = new Container([
10
            'a' => 1,
11
            'b' => 3,
12
            5 => 'z'
13
        ]);
14
15
        $this->assertTrue($testContainer->offsetExists('a'));
16
        $this->assertTrue($testContainer->offsetExists(5));
17
        $this->assertFalse($testContainer->offsetExists('c'));
18
        $this->assertFalse($testContainer->offsetExists(6));
19
20
        $this->assertTrue(isset($testContainer['a']));
21
        $this->assertTrue(isset($testContainer[5]));
22
        $this->assertFalse(isset($testContainer[99]));
23
    }
24
25
    public function testContainerGet()
26
    {
27
        $testContainer = new Container([
28
            'a' => 1,
29
            'b' => 3,
30
            5 => 'z'
31
        ]);
32
33
        $this->assertEquals(1, $testContainer['a']);
34
        $this->assertEquals('z', $testContainer[5]);
35
        $this->assertEquals(null, $testContainer['unknownValue']);
36
    }
37
38
    public function testContainerUnset()
39
    {
40
        $payload = [
41
            'a' => 1,
42
            'b' => 3,
43
            5 => 'z'
44
        ];
45
46
        $testContainer = new Container($payload);
47
        $this->assertSame(1, $testContainer['a']);
48
        $this->assertSame(3, $testContainer['b']);
49
        $this->assertSame('z', $testContainer['5']);
50
        unset($testContainer['b']);
51
        $this->assertFalse($testContainer->offsetExists('b'));
52
    }
53
54
    public function testContainerSet()
55
    {
56
        $testContainer = new Container();
57
        $this->assertEquals(null, $testContainer['myValue']);
58
        $testContainer['myValue'] = 42;
59
        $this->assertEquals(42, $testContainer['myValue']);
60
    }
61
}
62