Completed
Push — release/v1.0.0 ( 9b8046...eee318 )
by Edward
11:43
created

SeekableTraitTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 8
loc 52
rs 10

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 SeekableTraitTest.php
4
 *
5
 * @author Edward Pfremmer <[email protected]>
6
 */
7
namespace Epfremme\Tests\Collection\Traits;
8
9
use SeekableIterator;
10
use Epfremme\Collection\BaseCollection;
11
12
/**
13
 * Class SeekableTraitTest
14
 *
15
 * @package Epfremme\Tests\Collection\Traits
16
 */
17
class SeekableTraitTest 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(SeekableIterator::class, $this->collection);
42
    }
43
44
    /**
45
     * Test collection seek method
46
     *
47
     * @return void
48
     */
49
    public function testSeek()
50
    {
51
        $this->collection->seek('a');
52
        $this->assertEquals(4, $this->collection->current());
53
54
        $this->collection->seek(2);
55
        $this->assertEquals(3, $this->collection->current());
56
    }
57
58
    /**
59
     * Test invalid offset seek exception
60
     *
61
     * @expectedException \InvalidArgumentException
62
     * @return void
63
     */
64
    public function testSeekException()
65
    {
66
        $this->collection->seek('noop');
67
    }
68
}
69