Completed
Pull Request — master (#7)
by Harry
02:07
created

ContainerTest::testArrayAccessIsset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Graze\DataStructure\Container;
4
5
use PHPUnit_Framework_TestCase as TestCase;
6
7
class ContainerTest extends TestCase
8
{
9
    public function testInterface()
10
    {
11
        $cont = new Container();
12
13
        $this->assertInstanceOf('Graze\DataStructure\Container\ContainerInterface', $cont);
14
        $this->assertInstanceOf('Serializable', $cont);
15
    }
16
17 View Code Duplication
    public function testConstructor()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
    {
19
        $params = ['foo' => 'a', 'bar' => 'b', 'baz' => 'c'];
20
        $cont = new Container($params);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
21
22
        $this->assertEquals($params, $cont->getAll());
23
    }
24
25
    public function testAdd()
26
    {
27
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
28
        $result = $cont->add('baz', 'c');
29
30
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
31
        $this->assertSame($cont, $result);
32
    }
33
34
    /**
35
     * @expectedException \Graze\DataStructure\Exception\RegisteredKeyException
36
     */
37
    public function testAddDuplicate()
38
    {
39
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
40
41
        $cont->add('baz', 'd');
42
    }
43
44 View Code Duplication
    public function testForAll()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        $params = ['foo' => 'a', 'bar' => 'b', 'baz' => 'c'];
47
        $seen = [];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
48
49
        $cont = new Container($params);
50
        $cont->forAll(function ($value, $key) use (&$seen) {
51
            $seen[$key] = $value;
52
        });
53
54
        $this->assertEquals($params, $seen);
55
    }
56
57
    public function testGet()
58
    {
59
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
60
61
        $this->assertEquals('a', $cont->get('foo'));
62
    }
63
64
    public function testGetMissing()
65
    {
66
        $cont = new Container();
67
68
        $this->assertNull($cont->get('foo'));
69
    }
70
71
    public function testGetIterator()
72
    {
73
        $cont = new Container();
74
75
        $this->assertInstanceOf('Iterator', $cont->getIterator());
76
    }
77
78
    public function testHasIsTrue()
79
    {
80
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
81
82
        $this->assertTrue($cont->has('foo'));
83
    }
84
85
    public function testHasIsFalse()
86
    {
87
        $cont = new Container(['FOO' => 'a', 'bar' => 'b', 'baz' => 'c']);
88
89
        $this->assertFalse($cont->has('foo'));
90
    }
91
92 View Code Duplication
    public function testRemove()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
    {
94
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
95
        $result = $cont->remove('bar');
96
97
        $this->assertEquals(['foo' => 'a', 'baz' => 'c'], $cont->getAll());
98
        $this->assertSame($cont, $result);
99
    }
100
101 View Code Duplication
    public function testRemoveMissing()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
104
        $result = $cont->remove('baz');
105
106
        $this->assertEquals(['foo' => 'a', 'bar' => 'b'], $cont->getAll());
107
        $this->assertSame($cont, $result);
108
    }
109
110
    public function testSet()
111
    {
112
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
113
        $result = $cont->set('baz', 'c');
114
115
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
116
        $this->assertSame($cont, $result);
117
    }
118
119
    public function testSetDuplicate()
120
    {
121
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
122
        $result = $cont->set('baz', 'd');
123
124
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'd'], $cont->getAll());
125
        $this->assertSame($cont, $result);
126
    }
127
128
    public function testSerialize()
129
    {
130
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
131
132
        $this->assertEquals(
133
            'C:39:"Graze\DataStructure\Container\Container":60:{a:3:{s:3:"foo";s:1:"a";s:3:"bar";s:1:"b";s:3:"baz";s:1:"c";}}',
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
134
            serialize($cont)
135
        );
136
    }
137
138
    public function testUnserialize()
139
    {
140
        $cont = unserialize('C:39:"Graze\DataStructure\Container\Container":60:{a:3:{s:3:"foo";s:1:"a";s:3:"bar";s:1:"b";s:3:"baz";s:1:"c";}}');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 144 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
141
142
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
143
    }
144
145
    public function testArrayGet()
146
    {
147
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
148
149
        $this->assertEquals('a', $cont['foo']);
150
    }
151
152 View Code Duplication
    public function testArraySet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
153
    {
154
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
155
        $cont['baz'] = 'c';
156
157
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
158
    }
159
160
    public function testArrayHasIsTrue()
161
    {
162
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
163
164
        $this->assertTrue(isset($cont['foo']));
165
    }
166
167
    public function testArrayHasIsFalse()
168
    {
169
        $cont = new Container(['FOO' => 'a', 'bar' => 'b', 'baz' => 'c']);
170
171
        $this->assertFalse(isset($cont['foo']));
172
    }
173
174 View Code Duplication
    public function testArrayRemove()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
175
    {
176
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
177
        unset($cont['bar']);
178
179
        $this->assertEquals(['foo' => 'a', 'baz' => 'c'], $cont->getAll());
180
    }
181
182
    public function testArrayRemoveMissing()
183
    {
184
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
185
        unset($cont['baz']);
186
187
        $this->assertEquals(['foo' => 'a', 'bar' => 'b'], $cont->getAll());
188
    }
189
}
190