Completed
Pull Request — master (#7)
by Harry
01:43
created

ContainerTest::testArrayHasIsTrue()   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 ArrayAccess;
6
use PHPUnit_Framework_TestCase as TestCase;
7
use Serializable;
8
9
class ContainerTest extends TestCase
10
{
11
    public function testInterface()
12
    {
13
        $cont = new Container();
14
15
        $this->assertInstanceOf(ContainerInterface::class, $cont);
16
        $this->assertInstanceOf(Serializable::class, $cont);
17
        $this->assertInstanceOf(ArrayAccess::class, $cont);
18
    }
19
20 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...
21
    {
22
        $params = ['foo' => 'a', 'bar' => 'b', 'baz' => 'c'];
23
        $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...
24
25
        $this->assertEquals($params, $cont->getAll());
26
    }
27
28
    public function testAdd()
29
    {
30
        $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...
31
        $result = $cont->add('baz', 'c');
32
33
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
34
        $this->assertSame($cont, $result);
35
    }
36
37
    /**
38
     * @expectedException \Graze\DataStructure\Exception\RegisteredKeyException
39
     */
40
    public function testAddDuplicate()
41
    {
42
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
43
44
        $cont->add('baz', 'd');
45
    }
46
47 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...
48
    {
49
        $params = ['foo' => 'a', 'bar' => 'b', 'baz' => 'c'];
50
        $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...
51
52
        $cont = new Container($params);
53
        $cont->forAll(function ($value, $key) use (&$seen) {
54
            $seen[$key] = $value;
55
        });
56
57
        $this->assertEquals($params, $seen);
58
    }
59
60
    public function testGet()
61
    {
62
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
63
64
        $this->assertEquals('a', $cont->get('foo'));
65
    }
66
67
    public function testGetMissing()
68
    {
69
        $cont = new Container();
70
71
        $this->assertNull($cont->get('foo'));
72
    }
73
74
    public function testGetIterator()
75
    {
76
        $cont = new Container();
77
78
        $this->assertInstanceOf('Iterator', $cont->getIterator());
79
    }
80
81
    public function testHasIsTrue()
82
    {
83
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
84
85
        $this->assertTrue($cont->has('foo'));
86
    }
87
88
    public function testHasIsFalse()
89
    {
90
        $cont = new Container(['FOO' => 'a', 'bar' => 'b', 'baz' => 'c']);
91
92
        $this->assertFalse($cont->has('foo'));
93
    }
94
95 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...
96
    {
97
        $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...
98
        $result = $cont->remove('bar');
99
100
        $this->assertEquals(['foo' => 'a', 'baz' => 'c'], $cont->getAll());
101
        $this->assertSame($cont, $result);
102
    }
103
104 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...
105
    {
106
        $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...
107
        $result = $cont->remove('baz');
108
109
        $this->assertEquals(['foo' => 'a', 'bar' => 'b'], $cont->getAll());
110
        $this->assertSame($cont, $result);
111
    }
112
113
    public function testSet()
114
    {
115
        $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...
116
        $result = $cont->set('baz', 'c');
117
118
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
119
        $this->assertSame($cont, $result);
120
    }
121
122
    public function testSetDuplicate()
123
    {
124
        $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...
125
        $result = $cont->set('baz', 'd');
126
127
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'd'], $cont->getAll());
128
        $this->assertSame($cont, $result);
129
    }
130
131 View Code Duplication
    public function testSerialize()
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...
132
    {
133
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
134
135
        $this->assertEquals(
136
            '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...
137
            serialize($cont)
138
        );
139
    }
140
141
    public function testUnserialize()
142
    {
143
        $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...
144
145
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
146
    }
147
148
    public function testArrayGet()
149
    {
150
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
151
152
        $this->assertEquals('a', $cont['foo']);
153
    }
154
155 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...
156
    {
157
        $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...
158
        $cont['baz'] = 'c';
159
160
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
161
    }
162
163
    public function testArrayHasIsTrue()
164
    {
165
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
166
167
        $this->assertTrue(isset($cont['foo']));
168
    }
169
170
    public function testArrayHasIsFalse()
171
    {
172
        $cont = new Container(['FOO' => 'a', 'bar' => 'b', 'baz' => 'c']);
173
174
        $this->assertFalse(isset($cont['foo']));
175
    }
176
177 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...
178
    {
179
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
180
        unset($cont['bar']);
181
182
        $this->assertEquals(['foo' => 'a', 'baz' => 'c'], $cont->getAll());
183
    }
184
185
    public function testArrayRemoveMissing()
186
    {
187
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
188
        unset($cont['baz']);
189
190
        $this->assertEquals(['foo' => 'a', 'bar' => 'b'], $cont->getAll());
191
    }
192
}
193