IteratorTraitTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 73
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A valid() 0 5 1
A current() 0 5 1
A key() 0 5 1
A iterate() 0 19 2
1
<?php
2
namespace SubjectivePHPTest\Spl\Traits;
3
4
/**
5
 * @coversDefaultClass SubjectivePHP\Spl\Traits\IteratorTrait
6
 */
7
class IteratorTraitTest extends \PHPUnit\Framework\TestCase
8
{
9
    /**
10
     * Verify basic behavior of valid().
11
     *
12
     * @test
13
     * @covers ::valid
14
     *
15
     * @return void
16
     */
17
    public function valid()
18
    {
19
        $object = new SimpleObject();
20
        $this->assertFalse($object->valid());
21
    }
22
23
    /**
24
     * Verify basic behavior of current().
25
     *
26
     * @test
27
     * @covers ::current
28
     *
29
     * @return void
30
     */
31
    public function current()
32
    {
33
        $object = new SimpleObject(['foo' => 'bar']);
34
        $this->assertSame('bar', $object->current());
35
    }
36
37
    /**
38
     * Verify basic behavior of key().
39
     *
40
     * @test
41
     * @covers ::key
42
     *
43
     * @return void
44
     */
45
    public function key()
46
    {
47
        $object = new SimpleObject(['foo' => 'bar']);
48
        $this->assertSame('foo', $object->key());
49
    }
50
51
    /**
52
     * Verify basic use of iterator
53
     *
54
     * @test
55
     * @covers ::rewind
56
     * @covers ::next
57
     *
58
     * @return void
59
     */
60
    public function iterate()
61
    {
62
        $object = new SimpleObject(
63
            [
64
                'key0' => 'value0',
65
                'key1' => 'value1',
66
                'key2' => 'value2',
67
            ]
68
        );
69
70
        $count = 0;
71
        foreach ($object as $key => $value) {
72
            $this->assertSame("key{$count}", $key);
73
            $this->assertSame("value{$count}", $value);
74
            $count++;
75
        }
76
77
        $this->assertSame(3, $count);
78
    }
79
}
80