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\DoctrineORMAdminBundle\Tests\Datagrid; |
13
|
|
|
|
14
|
|
|
use Doctrine\ORM\AbstractQuery; |
15
|
|
|
use Doctrine\ORM\Query; |
16
|
|
|
use Doctrine\ORM\Tools\Pagination\CountWalker; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
use Sonata\DoctrineORMAdminBundle\Datagrid\Pager; |
19
|
|
|
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; |
20
|
|
|
use Sonata\DoctrineORMAdminBundle\Tests\Filter\QueryBuilder; |
21
|
|
|
|
22
|
|
|
class PagerTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
public function dataGetComputeNbResult() |
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
|
|
[true], |
28
|
|
|
[false], |
29
|
|
|
]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @dataProvider dataGetComputeNbResult |
34
|
|
|
* |
35
|
|
|
* @param bool $distinct |
36
|
|
|
*/ |
37
|
|
|
public function testComputeNbResult($distinct) |
38
|
|
|
{ |
39
|
|
|
$q = $this->getMockBuilder(AbstractQuery::class) |
40
|
|
|
->disableOriginalConstructor() |
41
|
|
|
->setMethods(['getSingleScalarResult', 'getHint', 'setHint']) |
42
|
|
|
->getMockForAbstractClass(); |
43
|
|
|
|
44
|
|
|
$q->expects($this->once()) |
45
|
|
|
->method('getSingleScalarResult'); |
46
|
|
|
|
47
|
|
|
$q->expects($this->once()) |
48
|
|
|
->method('getHint') |
49
|
|
|
->willReturn(null); |
50
|
|
|
|
51
|
|
|
$q->expects($this->exactly(2)) |
52
|
|
|
->method('setHint') |
53
|
|
|
->withConsecutive( |
54
|
|
|
[$this->equalTo(CountWalker::HINT_DISTINCT), $this->equalTo($distinct)], |
55
|
|
|
[$this->equalTo(Query::HINT_CUSTOM_TREE_WALKERS), $this->equalTo([CountWalker::class])] |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$qb = $this->getMockBuilder(QueryBuilder::class) |
59
|
|
|
->disableOriginalConstructor() |
60
|
|
|
->setMethods(['getQuery']) |
61
|
|
|
->getMock(); |
62
|
|
|
|
63
|
|
|
$qb->expects($this->once()) |
64
|
|
|
->method('getQuery') |
65
|
|
|
->willReturn($q); |
66
|
|
|
|
67
|
|
|
$pq = new ProxyQuery($qb); |
68
|
|
|
$pq->setDistinct($distinct); |
69
|
|
|
|
70
|
|
|
$pager = new Pager(); |
71
|
|
|
$pager->setQuery($pq); |
72
|
|
|
$pager->computeNbResult(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|