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\MediaBundle\Repository; |
||
4 | |||
5 | use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase; |
||
6 | use OpenOrchestra\Media\Repository\MediaRepositoryInterface; |
||
7 | use OpenOrchestra\ModelInterface\Repository\RepositoryTrait\KeywordableTraitInterface; |
||
8 | use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration; |
||
9 | |||
10 | /** |
||
11 | * Class MediaRepositoryTest |
||
12 | * |
||
13 | * @group integrationTest |
||
14 | */ |
||
15 | class MediaRepositoryTest extends AbstractKernelTestCase |
||
16 | { |
||
17 | /** |
||
18 | * @var MediaRepositoryInterface |
||
19 | */ |
||
20 | protected $repository; |
||
21 | protected $keywordRepository; |
||
22 | |||
23 | /** |
||
24 | * Set up test |
||
25 | */ |
||
26 | protected function setUp() |
||
27 | { |
||
28 | parent::setUp(); |
||
29 | |||
30 | static::bootKernel(); |
||
31 | $this->keywordRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.keyword'); |
||
32 | $this->repository = static::$kernel->getContainer()->get('open_orchestra_media.repository.media'); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param string $keywords |
||
37 | * @param int $count |
||
38 | * |
||
39 | * @dataProvider provideKeywordAndCount |
||
40 | */ |
||
41 | public function testFindByKeywords($keywords, $count) |
||
42 | { |
||
43 | $keywords = $this->replaceKeywordLabelById($keywords); |
||
44 | $keywords = $this->repository->findByKeywords($keywords); |
||
45 | |||
46 | $this->assertCount($count, $keywords); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @return array |
||
51 | */ |
||
52 | public function provideKeywordAndCount() |
||
53 | { |
||
54 | return array( |
||
55 | array('lorem', 5), |
||
56 | array('sit', 0), |
||
57 | array('dolor', 4), |
||
58 | array('lorem OR dolor', 5), |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param string $condition |
||
64 | * |
||
65 | * @return array |
||
66 | */ |
||
67 | View Code Duplication | protected function replaceKeywordLabelById($condition) |
|
68 | { |
||
69 | $conditionWithoutOperator = preg_replace(explode('|', KeywordableTraitInterface::OPERATOR_SPLIT), ' ', $condition); |
||
70 | $conditionArray = explode(' ', $conditionWithoutOperator); |
||
71 | |||
72 | foreach ($conditionArray as $keyword) { |
||
73 | if ($keyword != '') { |
||
74 | $keywordDocument = $this->keywordRepository->findOneByLabel($keyword); |
||
75 | if (!is_null($keywordDocument)) { |
||
76 | $condition = str_replace($keyword, $keywordDocument->getId(), $condition); |
||
77 | } else { |
||
78 | return ''; |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | |||
83 | return $condition; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * test findForPaginate |
||
88 | * |
||
89 | * @param string $siteId |
||
90 | * @param PaginateFinderConfiguration $configuration |
||
91 | * @param int $expectedCount |
||
92 | * @param int $expectedFilteredCount |
||
93 | * |
||
94 | * @dataProvider providePaginateConfiguration |
||
95 | */ |
||
96 | public function testFindForPaginate($siteId, PaginateFinderConfiguration $configuration, $expectedCount, $expectedFilteredCount) |
||
0 ignored issues
–
show
|
|||
97 | { |
||
98 | $this->assertCount($expectedCount, $this->repository->findForPaginate($configuration, $siteId)); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * test count |
||
103 | */ |
||
104 | public function testCount() |
||
105 | { |
||
106 | $this->assertSame(6, $this->repository->count('2')); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * test count with Filtertered |
||
111 | */ |
||
112 | public function testCountFiltered() |
||
113 | { |
||
114 | $this->assertSame(1, $this->repository->count('2', 'pdf')); |
||
0 ignored issues
–
show
The call to
MediaRepositoryInterface::count() has too many arguments starting with 'pdf' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
115 | $this->assertSame(5, $this->repository->count('2', 'image')); |
||
0 ignored issues
–
show
The call to
MediaRepositoryInterface::count() has too many arguments starting with 'image' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
116 | } |
||
117 | |||
118 | /** |
||
119 | * test countWithFilter |
||
120 | * |
||
121 | * @param string $siteId |
||
122 | * @param PaginateFinderConfiguration $configuration |
||
123 | * @param int $expectedCount |
||
124 | * @param int $expectedFilteredCount |
||
125 | * |
||
126 | * @dataProvider providePaginateConfiguration |
||
127 | */ |
||
128 | public function testCountWithFilter($siteId, PaginateFinderConfiguration $configuration, $expectedCount, $expectedFilteredCount) |
||
0 ignored issues
–
show
|
|||
129 | { |
||
130 | $this->assertSame($expectedFilteredCount, $this->repository->countWithFilter($configuration, $siteId)); |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * Provide PaginateFinderConfiguration |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | public function providePaginateConfiguration() |
||
139 | { |
||
140 | $mapping = array(); |
||
141 | $conf1 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, null); |
||
142 | $conf2 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, array('label' => 'dolor', 'language' => 'en')); |
||
143 | $conf3 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, array('type' => 'pdf')); |
||
144 | |||
145 | return array( |
||
146 | 'No criteria' => array('2', $conf1, 6, 6), |
||
147 | 'Filtering "dolor"' => array('2', $conf2, 4, 4), |
||
148 | 'Filtering pdf' => array('2', $conf3, 1, 1), |
||
149 | ); |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Test remove medias |
||
154 | */ |
||
155 | View Code Duplication | public function testRemoveMedias() |
|
156 | { |
||
157 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
158 | $image01 = $this->repository->findOneByName('Image 01'); |
||
159 | $image02 = $this->repository->findOneByName('Image 02'); |
||
160 | |||
161 | $mediaIds = array($image01->getId(), $image02->getId()); |
||
162 | |||
163 | $this->repository->removeMedias($mediaIds); |
||
164 | $this->assertNull($this->repository->findOneByName('Image 01')); |
||
165 | $this->assertNull($this->repository->findOneByName('Image 02')); |
||
166 | |||
167 | $dm->persist(clone $image01); |
||
168 | $dm->persist(clone $image02); |
||
169 | $dm->flush(); |
||
170 | } |
||
171 | } |
||
172 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.