Completed
Branch release/v1.0.0 (b932d7)
by Edward
03:07 queued 40s
created

IterableTraitTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 159
Duplicated Lines 23.9 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 1
cbo 2
dl 38
loc 159
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testImplementsInterface() 0 4 1
A testKey() 8 8 1
A testCurrent() 8 8 1
A testFirst() 0 7 1
A testLast() 0 6 1
A testNext() 11 11 1
A testPrev() 11 11 1
A testValid() 0 10 1
A testRewind() 0 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * File IterableTraitTest.php
4
 *
5
 * @author Edward Pfremmer <[email protected]>
6
 */
7
namespace Epfremme\Tests\Collection\Traits;
8
9
use Iterator;
10
use Epfremme\Collection\BaseCollection;
11
12
/**
13
 * Class IterableTraitTest
14
 *
15
 * @package Epfremme\Tests\Collection\Traits
16
 */
17
class IterableTraitTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @var BaseCollection
21
     */
22
    private $collection;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function setUp()
28
    {
29
        parent::setUp();
30
31
        $this->collection = new BaseCollection([1, 2, 3, 'a' => 4, 'b' => 5]);
32
    }
33
34
    /**
35
     * Verify collection implements ArrayAccess interface
36
     *
37
     * @return void
38
     */
39
    public function testImplementsInterface()
40
    {
41
        $this->assertInstanceOf(Iterator::class, $this->collection);
42
    }
43
44
    /**
45
     * Test collection key position
46
     *
47
     * @return void
48
     */
49 View Code Duplication
    public function testKey()
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...
50
    {
51
        $this->collection->seek(2);
52
        $this->assertEquals(2, $this->collection->key());
53
54
        $this->collection->seek('a');
55
        $this->assertEquals('a', $this->collection->key());
56
    }
57
58
    /**
59
     * Test collection current position
60
     *
61
     * @return void
62
     */
63 View Code Duplication
    public function testCurrent()
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...
64
    {
65
        $this->collection->seek(2);
66
        $this->assertEquals(3, $this->collection->current());
67
68
        $this->collection->seek('a');
69
        $this->assertEquals(4, $this->collection->current());
70
    }
71
72
    /**
73
     * Test collection first position
74
     *
75
     * @depends testKey
76
     * @depends testCurrent
77
     * @return void
78
     */
79
    public function testFirst()
80
    {
81
        $this->collection->seek(2);
82
        $this->collection->first();
83
        $this->assertEquals(0, $this->collection->key());
84
        $this->assertEquals(1, $this->collection->current());
85
    }
86
87
    /**
88
     * Test collection last position
89
     *
90
     * @depends testKey
91
     * @depends testCurrent
92
     * @return void
93
     */
94
    public function testLast()
95
    {
96
        $this->collection->last();
97
        $this->assertEquals('b', $this->collection->key());
98
        $this->assertEquals(5, $this->collection->current());
99
    }
100
101
    /**
102
     * Test collection next position
103
     *
104
     * @depends testKey
105
     * @depends testCurrent
106
     * @return void
107
     */
108 View Code Duplication
    public function testNext()
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...
109
    {
110
        $this->collection->next();
111
        $this->assertEquals(1, $this->collection->key());
112
        $this->assertEquals(2, $this->collection->current());
113
114
        $this->collection->last();
115
        $this->collection->next();
116
        $this->assertNull($this->collection->key());
117
        $this->assertFalse($this->collection->current());
118
    }
119
120
    /**
121
     * Test collection previous position
122
     *
123
     * @depends testKey
124
     * @depends testCurrent
125
     * @depends testNext
126
     * @return void
127
     */
128 View Code Duplication
    public function testPrev()
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...
129
    {
130
        $this->collection->next();
131
        $this->collection->prev();
132
        $this->assertEquals(0, $this->collection->key());
133
        $this->assertEquals(1, $this->collection->current());
134
135
        $this->collection->prev();
136
        $this->assertNull($this->collection->key());
137
        $this->assertFalse($this->collection->current());
138
    }
139
140
    /**
141
     * Test collection valid
142
     *
143
     * @depends testNext
144
     * @depends testLast
145
     * @return void
146
     */
147
    public function testValid()
148
    {
149
        $this->assertTrue($this->collection->valid());
150
151
        $this->collection->last();
152
        $this->assertTrue($this->collection->valid());
153
154
        $this->collection->next();
155
        $this->assertFalse($this->collection->valid());
156
    }
157
158
    /**
159
     * Test collection rewind
160
     *
161
     * @depends testKey
162
     * @depends testCurrent
163
     * @return void
164
     */
165
    public function testRewind()
166
    {
167
        $this->collection->last();
168
        $this->assertEquals('b', $this->collection->key());
169
        $this->assertEquals(5, $this->collection->current());
170
171
        $this->collection->rewind();
172
        $this->assertEquals(0, $this->collection->key());
173
        $this->assertEquals(1, $this->collection->current());
174
    }
175
}
176