These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Sonata Project package. |
||
5 | * |
||
6 | * (c) Thomas Rabaix <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Unit\Datagrid; |
||
13 | |||
14 | use Doctrine\ODM\PHPCR\Query\Query as PHPCRQuery; |
||
15 | use PHPUnit\Framework\TestCase; |
||
16 | use Sonata\DoctrinePHPCRAdminBundle\Datagrid\Pager; |
||
17 | |||
18 | class PagerTest extends TestCase |
||
19 | { |
||
20 | public function setUp() |
||
21 | { |
||
22 | $this->pager = new Pager(10); |
||
0 ignored issues
–
show
|
|||
23 | |||
24 | $this->proxyQuery = $this->getMockBuilder('Sonata\DoctrinePHPCRAdminBundle\Datagrid\ProxyQuery') |
||
0 ignored issues
–
show
The property
proxyQuery does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
25 | ->disableOriginalConstructor() |
||
26 | ->getMock(); |
||
27 | } |
||
28 | |||
29 | public function testInitNumPages() |
||
30 | { |
||
31 | $this->proxyQuery->expects($this->once()) |
||
32 | ->method('execute') |
||
33 | ->with([], PHPCRQuery::HYDRATE_PHPCR) |
||
34 | ->will($this->returnValue(range(0, 12))); |
||
35 | |||
36 | $this->proxyQuery->expects($this->once()) |
||
37 | ->method('setMaxResults') |
||
38 | ->with($this->equalTo(10)); |
||
39 | |||
40 | $this->proxyQuery->expects($this->once()) |
||
41 | ->method('setFirstResult') |
||
42 | ->with($this->equalTo(0)); |
||
43 | |||
44 | $this->pager->setQuery($this->proxyQuery); |
||
45 | $this->pager->init(); |
||
46 | |||
47 | $this->assertEquals(2, $this->pager->getLastPage()); |
||
48 | } |
||
49 | |||
50 | public function testInitOffset() |
||
51 | { |
||
52 | $this->proxyQuery->expects($this->once()) |
||
53 | ->method('execute') |
||
54 | ->with([], PHPCRQuery::HYDRATE_PHPCR) |
||
55 | ->will($this->returnValue(range(0, 12))); |
||
56 | |||
57 | $this->proxyQuery->expects($this->once()) |
||
58 | ->method('setMaxResults') |
||
59 | ->with($this->equalTo(10)); |
||
60 | |||
61 | // Asserting that the offset will be set correctly |
||
62 | $this->proxyQuery->expects($this->once()) |
||
63 | ->method('setFirstResult') |
||
64 | ->with($this->equalTo(10)); |
||
65 | |||
66 | $this->pager->setQuery($this->proxyQuery); |
||
67 | $this->pager->setPage(2); |
||
68 | $this->pager->init(); |
||
69 | |||
70 | $this->assertEquals(2, $this->pager->getLastPage()); |
||
71 | } |
||
72 | |||
73 | public function testNoPagesPerConfig() |
||
74 | { |
||
75 | $this->proxyQuery->expects($this->once()) |
||
76 | ->method('setMaxResults') |
||
77 | ->with($this->equalTo(0)); |
||
78 | |||
79 | $this->proxyQuery->expects($this->once()) |
||
80 | ->method('setFirstResult') |
||
81 | ->with($this->equalTo(0)); |
||
82 | |||
83 | $this->pager->setQuery($this->proxyQuery); |
||
84 | |||
85 | // Max per page 0 means no pagination |
||
86 | $this->pager->setMaxPerPage(0); |
||
87 | $this->pager->init(); |
||
88 | |||
89 | $this->assertEquals(0, $this->pager->getLastPage()); |
||
90 | } |
||
91 | |||
92 | public function testNoPagesForNoResults() |
||
93 | { |
||
94 | $this->proxyQuery->expects($this->once()) |
||
95 | ->method('execute') |
||
96 | ->with([], PHPCRQuery::HYDRATE_PHPCR) |
||
97 | ->will($this->returnValue([])); |
||
98 | |||
99 | $this->proxyQuery->expects($this->once()) |
||
100 | ->method('setMaxResults') |
||
101 | ->with($this->equalTo(0)); |
||
102 | $this->proxyQuery->expects($this->once()) |
||
103 | ->method('setFirstResult') |
||
104 | ->with($this->equalTo(0)); |
||
105 | |||
106 | $this->pager->setQuery($this->proxyQuery); |
||
107 | $this->pager->init(); |
||
108 | $this->AssertEquals(0, $this->pager->getLastPage()); |
||
109 | } |
||
110 | |||
111 | public function testInitNoQuery() |
||
112 | { |
||
113 | $this->setExpectedException('RuntimeException'); |
||
0 ignored issues
–
show
The method
setExpectedException() does not exist on Sonata\DoctrinePHPCRAdmi...Unit\Datagrid\PagerTest . Did you maybe mean setExpectedExceptionFromAnnotation() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise.
Loading history...
|
|||
114 | $this->pager->init(); |
||
115 | } |
||
116 | } |
||
117 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: