These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace OpenOrchestra\FunctionalTests\ModelBundle\Repository; |
||
4 | |||
5 | use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase; |
||
6 | use OpenOrchestra\ModelBundle\Repository\SiteRepository; |
||
7 | use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration; |
||
8 | |||
9 | /** |
||
10 | * Class SiteRepositoryTest |
||
11 | * |
||
12 | * @group integrationTest |
||
13 | */ |
||
14 | class SiteRepositoryTest extends AbstractKernelTestCase |
||
15 | { |
||
16 | /** |
||
17 | * @var SiteRepository |
||
18 | */ |
||
19 | protected $repository; |
||
20 | |||
21 | /** |
||
22 | * Set up test |
||
23 | */ |
||
24 | protected function setUp() |
||
25 | { |
||
26 | parent::setUp(); |
||
27 | |||
28 | static::bootKernel(); |
||
29 | $this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.site'); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @param string $domain |
||
34 | * @param array<string> $expectedSiteIds |
||
35 | * |
||
36 | * @dataProvider provideAliasDomain |
||
37 | */ |
||
38 | public function testFindByAliasDomain($domain, $expectedSiteIds) |
||
39 | { |
||
40 | $sites = $this->repository->findByAliasDomain($domain); |
||
41 | |||
42 | $this->assertIdsMatches($expectedSiteIds, $sites); |
||
43 | } |
||
44 | |||
45 | |||
46 | /** |
||
47 | * @param PaginateFinderConfiguration $configuration |
||
48 | * @param array|null $siteIds |
||
49 | * @param int $count |
||
50 | * |
||
51 | * @dataProvider providePaginateAndSearch |
||
52 | */ |
||
53 | public function testFindForPaginate(PaginateFinderConfiguration $configuration, $siteIds, $count) |
||
54 | { |
||
55 | $sites = $this->repository->findForPaginateFilterBySiteIds($configuration, $siteIds); |
||
56 | $this->assertCount($count, $sites); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return array |
||
61 | */ |
||
62 | View Code Duplication | public function providePaginateAndSearch() |
|
0 ignored issues
–
show
|
|||
63 | { |
||
64 | $configurationAll = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array()); |
||
65 | $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 1, array()); |
||
66 | $configurationSearch = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'demo')); |
||
67 | $configurationAllOrder = PaginateFinderConfiguration::generateFromVariable(array('name' => 'desc'), 0, 100, array()); |
||
68 | |||
69 | return array( |
||
70 | 'all' => array($configurationAll, null, 1), |
||
71 | 'all with site' => array($configurationAll, array('2'), 1), |
||
72 | 'all with deleted site' => array($configurationAll, array('3'), 0), |
||
73 | 'all without site' => array($configurationAll, array(), 0), |
||
74 | 'limit' => array($configurationLimit, null, 1), |
||
75 | 'search' => array($configurationSearch, null, 1), |
||
76 | 'search without site' => array($configurationSearch, array(), 0), |
||
77 | 'order' => array($configurationAllOrder, null, 1), |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * test count all site |
||
83 | */ |
||
84 | public function testCount() |
||
85 | { |
||
86 | $sites = $this->repository->countFilterBySiteIds(); |
||
87 | $this->assertEquals(1, $sites); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * test count all site with site ids |
||
92 | */ |
||
93 | public function testCountWithIds() |
||
94 | { |
||
95 | $sites = $this->repository->countFilterBySiteIds(array('2')); |
||
96 | $this->assertEquals(1, $sites); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param PaginateFinderConfiguration $configuration |
||
101 | * @param array|null $siteIds |
||
102 | * @param int $count |
||
103 | * |
||
104 | * @dataProvider provideCountWithFilter |
||
105 | */ |
||
106 | public function testCountWithFilter($configuration, $siteIds, $count) |
||
107 | { |
||
108 | $sites = $this->repository->countWithFilterAndSiteIds($configuration, $siteIds); |
||
109 | $this->assertEquals($count, $sites); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @return array |
||
114 | */ |
||
115 | View Code Duplication | public function provideCountWithFilter() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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.
Loading history...
|
|||
116 | { |
||
117 | $configurationAll = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array()); |
||
118 | $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 1, array()); |
||
119 | $configurationSearch = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'demo')); |
||
120 | $configurationAllOrder = PaginateFinderConfiguration::generateFromVariable(array('name' => 'desc'), 0, 100, array()); |
||
121 | |||
122 | return array( |
||
123 | 'all' => array($configurationAll, null, 1), |
||
124 | 'all with site' => array($configurationAll, array('2'), 1), |
||
125 | 'all with deleted site' => array($configurationAll, array('3'), 0), |
||
126 | 'all without site' => array($configurationAll, array(), 0), |
||
127 | 'limit' => array($configurationLimit, null, 1), |
||
128 | 'search' => array($configurationSearch, null, 1), |
||
129 | 'search without site' => array($configurationSearch, array(), 0), |
||
130 | 'order' => array($configurationAllOrder, null, 1), |
||
131 | ); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Check if the $sites ids matches $expectedIds |
||
136 | * |
||
137 | * @param array $expectedIds |
||
138 | * @param array $sites |
||
139 | * |
||
140 | * @return boolean |
||
141 | */ |
||
142 | protected function assertIdsMatches($expectedIds, $sites) |
||
143 | { |
||
144 | if (count($expectedIds) != count($sites)) { |
||
145 | |||
146 | return false; |
||
147 | } |
||
148 | |||
149 | foreach ($sites as $site) { |
||
150 | if (!in_array($site->getSiteId(), $expectedIds)) { |
||
151 | |||
152 | return false; |
||
153 | } |
||
154 | } |
||
155 | |||
156 | return true; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @return array |
||
161 | */ |
||
162 | public function provideAliasDomain() |
||
163 | { |
||
164 | return array( |
||
165 | array('front.pddv-openorchestra-master.eolas-services.com', array('2')), |
||
166 | array('fakeDomain', array()) |
||
167 | ); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Test find by site ids |
||
172 | */ |
||
173 | public function testFindBySiteIds() |
||
174 | { |
||
175 | $sites = $this->repository->findBySiteIds(array('3', '2')); |
||
176 | $this->assertCount(1, $sites); |
||
177 | } |
||
178 | } |
||
179 |
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.