1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FOS\ElasticaBundle\Tests; |
4
|
|
|
|
5
|
|
|
use FOS\ElasticaBundle\Repository; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Richard Miller <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
class RepositoryTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
View Code Duplication |
public function testThatFindCallsFindOnFinder() |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$testQuery = 'Test Query'; |
15
|
|
|
|
16
|
|
|
$finderMock = $this->getFinderMock($testQuery); |
17
|
|
|
$repository = new Repository($finderMock); |
18
|
|
|
$repository->find($testQuery); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testThatFindCallsFindOnFinderWithLimit() |
22
|
|
|
{ |
23
|
|
|
$testQuery = 'Test Query'; |
24
|
|
|
$testLimit = 20; |
25
|
|
|
|
26
|
|
|
$finderMock = $this->getFinderMock($testQuery, $testLimit); |
27
|
|
|
$repository = new Repository($finderMock); |
28
|
|
|
$repository->find($testQuery, $testLimit); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public function testThatFindPaginatedCallsFindPaginatedOnFinder() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$testQuery = 'Test Query'; |
34
|
|
|
|
35
|
|
|
$finderMock = $this->getFinderMock($testQuery, array(), 'findPaginated'); |
36
|
|
|
$repository = new Repository($finderMock); |
37
|
|
|
$repository->findPaginated($testQuery); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public function testThatCreatePaginatorCreatesAPaginatorViaFinder() |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$testQuery = 'Test Query'; |
43
|
|
|
|
44
|
|
|
$finderMock = $this->getFinderMock($testQuery, array(), 'createPaginatorAdapter'); |
45
|
|
|
$repository = new Repository($finderMock); |
46
|
|
|
$repository->createPaginatorAdapter($testQuery); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function testThatFindHybridCallsFindHybridOnFinder() |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$testQuery = 'Test Query'; |
52
|
|
|
|
53
|
|
|
$finderMock = $this->getFinderMock($testQuery, null, 'findHybrid'); |
54
|
|
|
$repository = new Repository($finderMock); |
55
|
|
|
$repository->findHybrid($testQuery); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public function testThatFindRawResultCallsFindRawResultOnFinder() |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$testQuery = 'Test Query'; |
61
|
|
|
|
62
|
|
|
$finderMock = $this->getFinderMock($testQuery, null, 'findRawResult'); |
63
|
|
|
$repository = new Repository($finderMock); |
64
|
|
|
$repository->findRawResult($testQuery); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
public function testThatFindRawPaginatedCallsFindRawPaginatedOnFinder() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$testQuery = 'Test Query'; |
70
|
|
|
|
71
|
|
|
$finderMock = $this->getFinderMock($testQuery, array(), 'findRawPaginated'); |
72
|
|
|
$repository = new Repository($finderMock); |
73
|
|
|
$repository->findRawPaginated($testQuery); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
View Code Duplication |
public function testThatCreateRawPaginatorCreatesAPaginatorViaFinder() |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
$testQuery = 'Test Query'; |
79
|
|
|
|
80
|
|
|
$finderMock = $this->getFinderMock($testQuery, array(), 'createRawPaginatorAdapter'); |
81
|
|
|
$repository = new Repository($finderMock); |
82
|
|
|
$repository->createRawPaginatorAdapter($testQuery); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $testQuery |
87
|
|
|
* @param mixed $testLimit |
88
|
|
|
* @param string $method |
89
|
|
|
* |
90
|
|
|
* @return \FOS\ElasticaBundle\Finder\TransformedFinder |
91
|
|
|
*/ |
92
|
|
|
private function getFinderMock($testQuery, $testLimit = null, $method = 'find') |
93
|
|
|
{ |
94
|
|
|
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder') |
95
|
|
|
->disableOriginalConstructor() |
96
|
|
|
->getMock(); |
97
|
|
|
$finderMock->expects($this->once()) |
98
|
|
|
->method($method) |
99
|
|
|
->with($this->equalTo($testQuery), $this->equalTo($testLimit)); |
100
|
|
|
|
101
|
|
|
return $finderMock; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.