Passed
Pull Request — master (#170)
by ARP
02:38
created

AbstractTDBMObjectTest::testEmptyResultIterator()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 23
rs 9.3888
cc 5
nc 5
nop 0
1
<?php
2
3
namespace TheCodingMachine\TDBM;
4
5
use PHPUnit\Framework\TestCase;
6
use function foo\func;
7
8
class AbstractTDBMObjectTest extends TestCase
9
{
10
    public function testGetManyToManyRelationshipDescriptor()
11
    {
12
        $object = new TDBMObject();
13
        $this->expectException(TDBMException::class);
14
        $this->expectExceptionMessage('Could not find many to many relationship descriptor key for "foo"');
15
        $object->_getManyToManyRelationshipDescriptor('foo');
16
    }
17
18
    public function testEmptyResultIterator()
19
    {
20
        $a = ResultIterator::createEmpyIterator();
21
        foreach ($a as $empty) {
22
            throw new \LogicException("Not supposed to iterate on an empty iterator.");
23
        }
24
        $this->assertEquals(0, $a->count());
25
        $this->assertEquals(null, $a->first());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $a->first() targeting TheCodingMachine\TDBM\ResultIterator::first() 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...
26
        $this->assertEquals(null, isset($a[0])); //an empty resultIterator must implement arrayAccess
27
        $this->assertEquals([], $a->toArray());
28
        foreach ($a->map(function($foo) {}) as $empty) {
0 ignored issues
show
Unused Code introduced by
The parameter $foo is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
        foreach ($a->map(function(/** @scrutinizer ignore-unused */ $foo) {}) as $empty) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
            throw new \LogicException("Not supposed to iterate on an empty iterator.");
30
        }
31
        $c = $a->withOrder("who cares");
32
        foreach ($c as $empty) {
33
            throw new \LogicException("Not supposed to iterate on an empty iterator.");
34
        }
35
        $this->assertEquals(0, $c->count());
36
        $d = $a->withParameters(["who cares"]);
37
        foreach ($d as $empty) {
38
            throw new \LogicException("Not supposed to iterate on an empty iterator.");
39
        }
40
        $this->assertEquals(0, $d->count());
41
    }
42
43
    public function testEmptyPageIterator()
44
    {
45
        $a = ResultIterator::createEmpyIterator();
46
        $b = $a->take(0, 10);
47
        foreach ($b as $empty) {
48
            throw new \LogicException("Not supposed to iterate on an empty page iterator.");
49
        }
50
        $this->assertEquals(0, $b->count());
51
        $this->assertEquals([], $b->toArray());
52
        $this->assertEquals(0, $b->totalCount());
53
        $c = $b->map(function($foo) {});
0 ignored issues
show
Unused Code introduced by
The parameter $foo is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

53
        $c = $b->map(function(/** @scrutinizer ignore-unused */ $foo) {});

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
        foreach ($c as $empty) {
55
            throw new \LogicException("Not supposed to iterate on an empty iterator.");
56
        }
57
        $this->assertEquals([], $c->toArray());
58
    }
59
}
60