Issues (291)

tests/AbstractTDBMObjectTest.php (4 issues)

1
<?php
2
3
namespace TheCodingMachine\TDBM;
4
5
use PHPUnit\Framework\TestCase;
6
7
use function foo\func;
0 ignored issues
show
The function foo\func was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
8
9
class AbstractTDBMObjectTest extends TestCase
10
{
11
    public function testGetManyToManyRelationshipDescriptor()
12
    {
13
        $object = new TDBMObject();
14
        $this->expectException(TDBMException::class);
15
        $this->expectExceptionMessage('Could not find many to many relationship descriptor key for "foo"');
16
        $object->_getManyToManyRelationshipDescriptor('foo');
17
    }
18
19
    public function testEmptyResultIterator()
20
    {
21
        $a = ResultIterator::createEmpyIterator();
22
        foreach ($a as $empty) {
23
            throw new \LogicException("Not supposed to iterate on an empty iterator.");
24
        }
25
        $this->assertEquals(0, $a->count());
26
        $this->assertEquals(null, $a->first());
0 ignored issues
show
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...
27
        $this->assertEquals(null, isset($a[0])); //an empty resultIterator must implement arrayAccess
28
        $this->assertEquals([], $a->toArray());
29
        foreach ($a->map(function ($foo) {
0 ignored issues
show
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

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

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