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

ImmutableFlatContainerTest::testRemoveMissing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Graze\DataStructure\Container;
4
5
use PHPUnit_Framework_TestCase as TestCase;
6
7
class ImmutableFlatContainerTest extends TestCase
8
{
9
    public function testInterface()
10
    {
11
        $cont = new ImmutableFlatContainer();
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 ImmutableFlatContainer($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 View Code Duplication
    public function testAdd()
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...
26
    {
27
        $cont = new ImmutableFlatContainer(['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'], $cont->getAll());
31
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $result->getAll());
32
        $this->assertNotSame($cont, $result);
33
        $this->assertInstanceOf(ImmutableFlatContainer::class, $result);
34
    }
35
36
    /**
37
     * @expectedException \Graze\DataStructure\Exception\RegisteredKeyException
38
     */
39
    public function testAddDuplicate()
40
    {
41
        $cont = new ImmutableFlatContainer(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
42
43
        $cont->add('baz', 'd');
44
    }
45
46
    public function testForAll()
47
    {
48
        $params = ['foo' => 'a', 'bar' => 'b', 'baz' => 'c'];
49
        $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...
50
51
        $cont = new ImmutableFlatContainer($params);
52
        $cont->forAll(function ($value, $key) use (&$seen) {
53
            $seen[$key] = $value;
54
        });
55
56
        $this->assertEquals($params, $seen);
57
    }
58
59
    public function testGet()
60
    {
61
        $cont = new ImmutableFlatContainer(['foo' => ['child' => 'a'], 'bar' => 'b', 'baz' => 'c']);
62
63
        $this->assertEquals('a', $cont->get('foo.child'));
64
    }
65
66
    public function testGetMissing()
67
    {
68
        $cont = new ImmutableFlatContainer();
69
70
        $this->assertNull($cont->get('foo'));
71
    }
72
73
    public function testGetIterator()
74
    {
75
        $cont = new ImmutableFlatContainer();
76
77
        $this->assertInstanceOf('Iterator', $cont->getIterator());
78
    }
79
80
    public function testHasIsTrue()
81
    {
82
        $cont = new ImmutableFlatContainer(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
83
84
        $this->assertTrue($cont->has('foo'));
85
    }
86
87
    public function testHasIsFalse()
88
    {
89
        $cont = new ImmutableFlatContainer(['FOO' => 'a', 'bar' => 'b', 'baz' => 'c']);
90
91
        $this->assertFalse($cont->has('foo'));
92
    }
93
94
    public function testRemove()
95
    {
96
        $cont = new ImmutableFlatContainer(['foo' => 'a', 'bar' => ['b' => 'c', 'd' => 'e'], '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...
97
        $result = $cont->remove('bar.b');
98
99
        $this->assertEquals(['foo' => 'a', 'bar' => ['b' => 'c', 'd' => 'e'], 'baz' => 'c'], $cont->getAll());
100
        $this->assertEquals(['foo' => 'a', 'bar' => ['d' => 'e'], 'baz' => 'c'], $result->getAll());
101
        $this->assertNotSame($cont, $result);
102
        $this->assertInstanceOf(ImmutableFlatContainer::class, $result);
103
    }
104
105 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...
106
    {
107
        $cont = new ImmutableFlatContainer(['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...
108
        $result = $cont->remove('baz');
109
110
        $this->assertEquals(['foo' => 'a', 'bar' => 'b'], $cont->getAll());
111
        $this->assertEquals(['foo' => 'a', 'bar' => 'b'], $result->getAll());
112
        $this->assertSame($cont, $result);
113
        $this->assertInstanceOf(ImmutableFlatContainer::class, $result);
114
    }
115
116
    public function testSet()
117
    {
118
        $cont = new ImmutableFlatContainer(['foo' => 'a', 'bar' => ['b' => '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...
119
        $result = $cont->set('bar.d', 'e');
120
121
        $this->assertEquals(['foo' => 'a', 'bar' => ['b' => 'c']], $cont->getAll());
122
        $this->assertEquals(['foo' => 'a', 'bar' => ['b' => 'c', 'd' => 'e']], $result->getAll());
123
        $this->assertNotSame($cont, $result);
124
        $this->assertInstanceOf(ImmutableFlatContainer::class, $result);
125
    }
126
127
    public function testSetDuplicate()
128
    {
129
        $cont = new ImmutableFlatContainer(['foo' => 'a', 'bar' => ['b' => 'c', 'd' => 'e']]);
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...
130
        $result = $cont->set('bar.d', 'f');
131
132
        $this->assertEquals(['foo' => 'a', 'bar' => ['b' => 'c', 'd' => 'e']], $cont->getAll());
133
        $this->assertEquals(['foo' => 'a', 'bar' => ['b' => 'c', 'd' => 'f']], $result->getAll());
134
        $this->assertNotSame($cont, $result);
135
        $this->assertInstanceOf(ImmutableFlatContainer::class, $result);
136
    }
137
138 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...
139
    {
140
        $cont = new ImmutableFlatContainer(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
141
142
        $this->assertEquals(
143
            'C:52:"Graze\DataStructure\Container\ImmutableFlatContainer":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 140 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
            serialize($cont)
145
        );
146
    }
147
148
    public function testUnserialize()
149
    {
150
        $cont = unserialize('C:52:"Graze\DataStructure\Container\ImmutableFlatContainer":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 157 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...
151
152
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
153
    }
154
155 View Code Duplication
    public function testArrayAccessUnset()
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 ImmutableFlatContainer(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
158
159
        unset($cont['baz']);
160
        $this->assertTrue($cont->has('baz'));
161
    }
162
163 View Code Duplication
    public function testArrayAccessSet()
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...
164
    {
165
        $cont = new ImmutableFlatContainer(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
166
167
        $cont['baz'] = 'd';
168
        $this->assertEquals('c', $cont->get('baz'));
169
    }
170
}
171