Passed
Pull Request — master (#179)
by David
02:35
created

EmptyInnerResultIteratorTest::testOffsetGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\TDBM;
4
5
use PHPUnit\Framework\TestCase;
6
7
class EmptyInnerResultIteratorTest extends TestCase
8
{
9
    public function testOffsetUnset()
10
    {
11
        $iterator = new EmptyInnerResultIterator();
12
        $this->expectException(TDBMInvalidOperationException::class);
13
        unset($iterator[42]);
14
    }
15
16
    public function testCount()
17
    {
18
        $iterator = new EmptyInnerResultIterator();
19
        $this->assertCount(0, $iterator);
20
    }
21
22
    public function testOffsetExists()
23
    {
24
        $iterator = new EmptyInnerResultIterator();
25
        $this->assertFalse(isset($iterator[0]));
26
    }
27
28
    public function testOffsetSet()
29
    {
30
        $iterator = new EmptyInnerResultIterator();
31
        $this->expectException(TDBMInvalidOperationException::class);
32
        $iterator[42] = 'foo';
33
    }
34
35
    public function testIterate()
36
    {
37
        $iterator = new EmptyInnerResultIterator();
38
        foreach ($iterator as $elem) {
39
            $this->fail('Iterator should be empty');
40
        }
41
42
        $iterator->next();
43
        $this->assertNull($iterator->current());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $iterator->current() targeting TheCodingMachine\TDBM\Em...sultIterator::current() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
44
        $this->assertNull($iterator->key());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $iterator->key() targeting TheCodingMachine\TDBM\Em...erResultIterator::key() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
45
    }
46
47
    public function testOffsetGet()
48
    {
49
        $iterator = new EmptyInnerResultIterator();
50
        $this->expectException(TDBMInvalidOffsetException::class);
51
        $iterator[42];
52
    }
53
}
54