Completed
Push — master ( e0017c...6b1304 )
by Tom
14s queued 11s
created

Paginator/Adapter/SelectableAdapterTest.php (42 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModuleTest\Paginator\Adapter;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Criteria;
9
use DoctrineModule\Paginator\Adapter\Selectable as SelectableAdapter;
10
use PHPUnit\Framework\TestCase;
11
use function range;
12
13
/**
14
 * Tests for the Selectable pagination adapter
15
 *
16
 * @link    http://www.doctrine-project.org/
17
 */
18
class SelectableAdapterTest extends TestCase
19
{
20
    /**
21
     * @covers \DoctrineModule\Paginator\Adapter\Selectable::getItems
22
     */
23
    public function testGetItemsAtOffsetZeroWithEmptyCriteria() : void
24
    {
25
        $selectable = $this->createMock('Doctrine\Common\Collections\Selectable');
0 ignored issues
show
Are you sure the assignment to $selectable is correct as $this->createMock('Doctr...llections\\Selectable') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
26
        $adapter    = new SelectableAdapter($selectable);
0 ignored issues
show
$selectable is of type null, but the function expects a object<Doctrine\Common\Collections\Selectable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
28
        $me = $this;
29
30
        $selectable
0 ignored issues
show
The method expects cannot be called on $selectable (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
31
            ->expects($this->once())
0 ignored issues
show
The method once() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
            ->method('matching')
33
            ->with(
34
                $this->callback(
0 ignored issues
show
The method callback() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
                    static function (Criteria $criteria) use ($me) {
36
                        $me->assertEquals(0, $criteria->getFirstResult());
37
                        $me->assertEquals(10, $criteria->getMaxResults());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
39
                        return true;
40
                    }
41
                )
42
            )
43
            ->will($this->returnValue(new ArrayCollection(range(1, 10))));
0 ignored issues
show
The method returnValue() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
45
        $expected = range(1, 10);
46
        $actual   = $adapter->getItems(0, 10);
47
48
        $this->assertEquals($expected, $actual);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
    }
50
51
    /**
52
     * @covers \DoctrineModule\Paginator\Adapter\Selectable::getItems
53
     */
54
    public function testGetItemsAtOffsetZeroWithNonEmptyCriteria() : void
55
    {
56
        $selectable = $this->createMock('Doctrine\Common\Collections\Selectable');
0 ignored issues
show
Are you sure the assignment to $selectable is correct as $this->createMock('Doctr...llections\\Selectable') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
57
        $criteria   = new Criteria(Criteria::expr()->eq('foo', 'bar'));
58
        $adapter    = new SelectableAdapter($selectable, $criteria);
0 ignored issues
show
$selectable is of type null, but the function expects a object<Doctrine\Common\Collections\Selectable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
60
        $me = $this;
61
62
        $selectable->expects($this->once())
0 ignored issues
show
The method once() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method expects cannot be called on $selectable (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
63
            ->method('matching')
64
            ->with(
65
                $this->callback(
0 ignored issues
show
The method callback() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
                    static function (Criteria $innerCriteria) use ($criteria, $me) {
67
                        // Criteria are cloned internally
68
                        $me->assertNotEquals($innerCriteria, $criteria);
0 ignored issues
show
The method assertNotEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
                        $me->assertEquals(0, $innerCriteria->getFirstResult());
70
                        $me->assertEquals(10, $innerCriteria->getMaxResults());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
                        $me->assertEquals($innerCriteria->getWhereExpression(), $criteria->getWhereExpression());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
73
                        return true;
74
                    }
75
                )
76
            )
77
            ->will($this->returnValue(new ArrayCollection(range(1, 10))));
0 ignored issues
show
The method returnValue() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
79
        $expected = range(1, 10);
80
        $actual   = $adapter->getItems(0, 10);
81
82
        $this->assertEquals($expected, $actual);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
    }
84
85
    /**
86
     * @covers \DoctrineModule\Paginator\Adapter\Selectable::getItems
87
     */
88
    public function testGetItemsAtOffsetTenWithEmptyCriteria() : void
89
    {
90
        $selectable = $this->createMock('Doctrine\Common\Collections\Selectable');
0 ignored issues
show
Are you sure the assignment to $selectable is correct as $this->createMock('Doctr...llections\\Selectable') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
91
        $adapter    = new SelectableAdapter($selectable);
0 ignored issues
show
$selectable is of type null, but the function expects a object<Doctrine\Common\Collections\Selectable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
92
93
        $me = $this;
94
95
        $selectable->expects($this->once())
0 ignored issues
show
The method once() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method expects cannot be called on $selectable (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
96
            ->method('matching')
97
            ->with(
98
                $this->callback(
0 ignored issues
show
The method callback() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
                    static function (Criteria $criteria) use ($me) {
100
                        $me->assertEquals(10, $criteria->getFirstResult());
101
                        $me->assertEquals(10, $criteria->getMaxResults());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
102
103
                        return true;
104
                    }
105
                )
106
            )
107
            ->will($this->returnValue(new ArrayCollection(range(11, 20))));
0 ignored issues
show
The method returnValue() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
109
        $expected = range(11, 20);
110
        $actual   = $adapter->getItems(10, 10);
111
112
        $this->assertEquals($expected, $actual);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
113
    }
114
115
    /**
116
     * @covers \DoctrineModule\Paginator\Adapter\Selectable::getItems
117
     */
118
    public function testGetItemsAtOffsetTenWithNonEmptyCriteria() : void
119
    {
120
        $selectable = $this->createMock('Doctrine\Common\Collections\Selectable');
0 ignored issues
show
Are you sure the assignment to $selectable is correct as $this->createMock('Doctr...llections\\Selectable') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
121
        $criteria   = new Criteria(Criteria::expr()->eq('foo', 'bar'));
122
        $adapter    = new SelectableAdapter($selectable, $criteria);
0 ignored issues
show
$selectable is of type null, but the function expects a object<Doctrine\Common\Collections\Selectable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
124
        $me = $this;
125
126
        $selectable->expects($this->once())
0 ignored issues
show
The method once() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method expects cannot be called on $selectable (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
127
            ->method('matching')
128
            ->with(
129
                $this->callback(
0 ignored issues
show
The method callback() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
130
                    static function (Criteria $innerCriteria) use ($criteria, $me) {
131
                        // Criteria are cloned internally
132
                        $me->assertNotEquals($innerCriteria, $criteria);
0 ignored issues
show
The method assertNotEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
133
                        $me->assertEquals(10, $innerCriteria->getFirstResult());
134
                        $me->assertEquals(10, $innerCriteria->getMaxResults());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
135
                        $me->assertEquals($innerCriteria->getWhereExpression(), $criteria->getWhereExpression());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
136
137
                        return true;
138
                    }
139
                )
140
            )
141
            ->will($this->returnValue(new ArrayCollection(range(11, 20))));
0 ignored issues
show
The method returnValue() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
142
143
        $expected = range(11, 20);
144
        $actual   = $adapter->getItems(10, 10);
145
146
        $this->assertEquals($expected, $actual);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
147
    }
148
149
    /**
150
     * @covers \DoctrineModule\Paginator\Adapter\Selectable::count
151
     */
152
    public function testReturnsCorrectCount() : void
153
    {
154
        $selectable = $this->createMock('Doctrine\Common\Collections\Selectable');
0 ignored issues
show
Are you sure the assignment to $selectable is correct as $this->createMock('Doctr...llections\\Selectable') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
155
        $expression = Criteria::expr()->eq('foo', 'bar');
156
        $criteria   = new Criteria($expression, ['baz' => Criteria::DESC], 10, 20);
157
        $adapter    = new SelectableAdapter($selectable, $criteria);
0 ignored issues
show
$selectable is of type null, but the function expects a object<Doctrine\Common\Collections\Selectable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
158
159
        $selectable->expects($this->once())
0 ignored issues
show
The method once() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method expects cannot be called on $selectable (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
160
            ->method('matching')
161
            ->with(
162
                $this->callback(
0 ignored issues
show
The method callback() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
163
                    static function (Criteria $criteria) use ($expression) {
164
                        return $criteria->getWhereExpression() === $expression
165
                            && ($criteria->getOrderings() === ['baz' => Criteria::DESC])
166
                            && $criteria->getFirstResult() === null
167
                            && $criteria->getMaxResults() === null;
168
                    }
169
                )
170
            )
171
            ->will($this->returnValue(new ArrayCollection(range(1, 101))));
0 ignored issues
show
The method returnValue() does not seem to exist on object<DoctrineModuleTes...\SelectableAdapterTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
172
173
        $this->assertEquals(101, $adapter->count());
174
175
        $this->assertSame(10, $criteria->getFirstResult(), 'Original criteria was not modified');
176
        $this->assertSame(20, $criteria->getMaxResults(), 'Original criteria was not modified');
177
    }
178
}
179