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 PaginateFinderConfiguration $configuration |
||
90 | * @param int $expectedCount |
||
91 | * @param int $expectedFilteredCount |
||
92 | * |
||
93 | * @dataProvider providePaginateConfiguration |
||
94 | */ |
||
95 | public function testFindForPaginate(PaginateFinderConfiguration $configuration, $expectedCount, $expectedFilteredCount) |
||
96 | { |
||
97 | $this->assertCount($expectedCount, $this->repository->findForPaginate($configuration)); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * test count |
||
102 | */ |
||
103 | public function testCount() |
||
104 | { |
||
105 | $this->assertSame(6, $this->repository->count()); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * test count with Filtertered |
||
110 | */ |
||
111 | public function testCountFiltered() |
||
112 | { |
||
113 | $this->assertSame(1, $this->repository->count('pdf')); |
||
0 ignored issues
–
show
|
|||
114 | $this->assertSame(5, $this->repository->count('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...
|
|||
115 | } |
||
116 | |||
117 | /** |
||
118 | * test countWithFilter |
||
119 | * |
||
120 | * @param PaginateFinderConfiguration $configuration |
||
121 | * @param int $expectedCount |
||
122 | * @param int $expectedFilteredCount |
||
123 | * |
||
124 | * @dataProvider providePaginateConfiguration |
||
125 | */ |
||
126 | public function testCountWithFilter(PaginateFinderConfiguration $configuration, $expectedCount, $expectedFilteredCount) |
||
127 | { |
||
128 | $this->assertSame($expectedFilteredCount, $this->repository->countWithFilter($configuration)); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Provide PaginateFinderConfiguration |
||
133 | * |
||
134 | * @return array |
||
135 | */ |
||
136 | public function providePaginateConfiguration() |
||
137 | { |
||
138 | $mapping = array(); |
||
139 | $conf1 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, null); |
||
140 | $conf2 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, array('label' => 'dolor', 'language' => 'en')); |
||
141 | $conf3 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, array('type' => 'pdf')); |
||
142 | |||
143 | return array( |
||
144 | 'No criteria' => array($conf1, 6, 6), |
||
145 | 'Filtering "dolor"' => array($conf2, 4, 4), |
||
146 | 'Filtering pdf' => array($conf3, 1, 1), |
||
147 | ); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * Test remove medias |
||
152 | */ |
||
153 | View Code Duplication | public function testRemoveMedias() |
|
154 | { |
||
155 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
156 | $image01 = $this->repository->findOneByName('Image 01'); |
||
157 | $image02 = $this->repository->findOneByName('Image 02'); |
||
158 | |||
159 | $mediaIds = array($image01->getId(), $image02->getId()); |
||
160 | |||
161 | $this->repository->removeMedias($mediaIds); |
||
162 | $this->assertNull($this->repository->findOneByName('Image 01')); |
||
163 | $this->assertNull($this->repository->findOneByName('Image 02')); |
||
164 | |||
165 | $dm->persist(clone $image01); |
||
166 | $dm->persist(clone $image02); |
||
167 | $dm->flush(); |
||
168 | } |
||
169 | } |
||
170 |
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
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.