Completed
Push — master ( 42e2f4...06fa71 )
by David
15s queued 12s
created

AbstractTDBMObjectTest::testEmptyPageIterator()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 16
rs 9.9
cc 3
nc 3
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) {
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) {

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
        }) as $empty) {
30
            throw new \LogicException("Not supposed to iterate on an empty iterator.");
31
        }
32
        $c = $a->withOrder("who cares");
33
        foreach ($c as $empty) {
34
            throw new \LogicException("Not supposed to iterate on an empty iterator.");
35
        }
36
        $this->assertEquals(0, $c->count());
37
        $d = $a->withParameters(["who cares"]);
38
        foreach ($d as $empty) {
39
            throw new \LogicException("Not supposed to iterate on an empty iterator.");
40
        }
41
        $this->assertEquals(0, $d->count());
42
    }
43
44
    public function testEmptyPageIterator()
45
    {
46
        $a = ResultIterator::createEmpyIterator();
47
        $b = $a->take(0, 10);
48
        foreach ($b as $empty) {
49
            throw new \LogicException("Not supposed to iterate on an empty page iterator.");
50
        }
51
        $this->assertEquals(0, $b->count());
52
        $this->assertEquals([], $b->toArray());
53
        $this->assertEquals(0, $b->totalCount());
54
        $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

54
        $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...
55
        });
56
        foreach ($c as $empty) {
57
            throw new \LogicException("Not supposed to iterate on an empty iterator.");
58
        }
59
        $this->assertEquals([], $c->toArray());
60
    }
61
}
62