Completed
Push — master ( 5f25ab...068d7d )
by Mathieu
06:40 queued 04:51
created

ContainerTest::testContainerExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.9
1
<?php
2
class ContainerTest extends \PHPUnit\Framework\TestCase
3
{
4
    public function testContainerExists()
5
    {
6
        $testContainer = new \Suricate\Container([
7
            'a' => 1,
8
            'b' => 3,
9
            5 => 'z'
10
        ]);
11
        
12
        
13
        $this->assertTrue($testContainer->offsetExists('a'));
14
        $this->assertTrue($testContainer->offsetExists(5));
15
        $this->assertFalse($testContainer->offsetExists('c'));
16
        $this->assertFalse($testContainer->offsetExists(6));
17
18
        $this->assertTrue(isset($testContainer['a']));
19
        $this->assertTrue(isset($testContainer[5]));
20
        $this->assertFalse(isset($testContainer[99]));
21
    }
22
23
    public function testContainerGet()
24
    {
25
        $testContainer = new \Suricate\Container([
26
            'a' => 1,
27
            'b' => 3,
28
            5 => 'z'
29
        ]);        
30
        
31
        $this->assertEquals($testContainer['a'], 1);
32
        $this->assertEquals($testContainer[5], 'z');
33
34
        $this->expectException(\InvalidArgumentException::class);
35
        $testContainer['zz'];
36
    }
37
38
    public function testContainerSet()
39
    {
40
        $payload = [
41
            'a' => 1,
42
            'b' => 3,
43
            5 => 'z'
44
        ];
45
46
        $warehouse = ['zz' => 'my_value'];
47
        
48
        $testContainer = new \Suricate\Container($payload);
49
50
        $reflector = new ReflectionClass(get_class($testContainer));
51
        $property = $reflector->getProperty('warehouse');
52
        $property->setAccessible(true);
53
54
        $this->assertEquals([], $property->getValue($testContainer));
55
56
        $property = $reflector->getProperty('content');
57
        $property->setAccessible(true);
58
        $this->assertEquals($payload, $property->getValue($testContainer));
59
60
        $testContainer['new_index'] = 'ttt';
61
        $this->assertEquals($payload, $property->getValue($testContainer));
62
63
        $testContainer->setWarehouse($warehouse);
64
        $property = $reflector->getProperty('warehouse');
65
        $property->setAccessible(true);
66
67
        $this->assertEquals($warehouse, $property->getValue($testContainer));
68
69
70
    }
71
72
    public function testContainerUnset()
73
    {
74
        $payload = [
75
            'a' => 1,
76
            'b' => 3,
77
            5 => 'z'
78
        ];
79
80
        $testContainer = new \Suricate\Container($payload);
81
        $this->assertAttributeEquals($payload, 'content', $testContainer);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertAttributeEquals() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3338 ( Ignorable by Annotation )

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

81
        /** @scrutinizer ignore-deprecated */ $this->assertAttributeEquals($payload, 'content', $testContainer);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
82
        unset($testContainer['b']);
83
        $this->assertAttributeEquals( [
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertAttributeEquals() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3338 ( Ignorable by Annotation )

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

83
        /** @scrutinizer ignore-deprecated */ $this->assertAttributeEquals( [

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
84
            'a' => 1,
85
            5 => 'z'
86
        ], 'content', $testContainer);
87
    }
88
89
    public function testContainerWarehouse()
90
    {
91
        $warehouse = ['test' => 'stdClass'];
92
93
        $testContainer = new \Suricate\Container([]);
94
        $testContainer->setWarehouse($warehouse);
95
        $this->assertEquals($testContainer['test'], new \stdClass);
96
    }
97
}
98