1 | <?php |
||
29 | class ElementIndexSettingsTest extends BaseTest |
||
30 | { |
||
31 | /** |
||
32 | * @var ElementIndexSettings |
||
33 | */ |
||
34 | private $schematicElementIndexSettingsService; |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function setUp() |
||
40 | { |
||
41 | $this->schematicElementIndexSettingsService = new ElementIndexSettings(); |
||
42 | $this->setMockSources(); |
||
43 | $this->setMockFieldsService(); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return ElementsService|Mock |
||
48 | * |
||
49 | * @param array $getAllElementTypesResponse |
||
50 | * |
||
51 | * @return Mock |
||
52 | */ |
||
53 | protected function getMockElementsService($getAllElementTypesResponse = []) |
||
60 | |||
61 | /** |
||
62 | * @return ElementIndexesService|Mock |
||
63 | * |
||
64 | * @param array $getSettingsResponse |
||
|
|||
65 | * |
||
66 | * @return Mock |
||
67 | */ |
||
68 | protected function getMockElementIndexesService() |
||
69 | { |
||
70 | $getSettingsResponse = $this->getElementIndexSettingsSavedData(); |
||
71 | $mock = $this->getMockBuilder(ElementIndexesService::class)->getMock(); |
||
72 | $mock->expects($this->any())->method('getSettings')->willReturn($getSettingsResponse['Entry']); |
||
73 | $mock->expects($this->any())->method('saveSettings')->willReturn(false); |
||
74 | |||
75 | return $mock; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Test default import functionality. |
||
80 | * |
||
81 | * @covers ::import |
||
82 | */ |
||
83 | public function testImport() |
||
84 | { |
||
85 | $data = $this->getElementIndexSettingsExportedData(); |
||
86 | $mockElementIndexesService = $this->getMockElementIndexesService(); |
||
87 | $this->setComponent(Craft::app(), 'elementIndexes', $mockElementIndexesService); |
||
88 | |||
89 | $import = $this->schematicElementIndexSettingsService->import($data); |
||
90 | |||
91 | $this->assertTrue($import instanceof Result); |
||
92 | $this->assertTrue($import->hasErrors()); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Test export functionality. |
||
97 | * |
||
98 | * @covers ::export |
||
99 | */ |
||
100 | public function testExport() |
||
101 | { |
||
102 | $data = $this->getElementsData(); |
||
103 | $mockElementsService = $this->getMockElementsService($data); |
||
104 | $this->setComponent(Craft::app(), 'elements', $mockElementsService); |
||
105 | |||
106 | $data = $this->getElementIndexSettingsExportedData(); |
||
107 | $mockElementIndexesService = $this->getMockElementIndexesService(); |
||
108 | $this->setComponent(Craft::app(), 'elementIndexes', $mockElementIndexesService); |
||
109 | |||
110 | $export = $this->schematicElementIndexSettingsService->export(); |
||
111 | $this->assertEquals($data, $export); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Returns elements data. |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | public function getElementsData() |
||
126 | |||
127 | /** |
||
128 | * Returns element index settings saved data. |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | private function getElementIndexSettingsSavedData() |
||
133 | { |
||
134 | return [ |
||
135 | 'Category' => [ |
||
136 | 'sources' => [ |
||
137 | '*' => [ |
||
138 | 'tableAttributes' => [ |
||
139 | '1' => 'section', |
||
140 | '2' => 'postDate', |
||
141 | '3' => 'expiryDate', |
||
142 | '4' => 'author', |
||
143 | '5' => 'link', |
||
144 | '6' => 'field:1', |
||
145 | ], |
||
146 | ], |
||
147 | ], |
||
148 | ], |
||
149 | 'Entry' => [ |
||
150 | 'sources' => [ |
||
151 | '*' => [ |
||
152 | 'tableAttributes' => [ |
||
153 | '1' => 'section', |
||
154 | '2' => 'postDate', |
||
155 | '3' => 'expiryDate', |
||
156 | '4' => 'author', |
||
157 | '5' => 'link', |
||
158 | ], |
||
159 | ], |
||
160 | ], |
||
161 | ], |
||
162 | ]; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * Returns element index settings exported data. |
||
167 | * |
||
168 | * @return array |
||
169 | */ |
||
170 | private function getElementIndexSettingsExportedData() |
||
171 | { |
||
172 | return [ |
||
173 | 'Category' => [ |
||
174 | 'sources' => [ |
||
175 | '*' => [ |
||
176 | 'tableAttributes' => [ |
||
177 | '1' => 'section', |
||
178 | '2' => 'postDate', |
||
179 | '3' => 'expiryDate', |
||
180 | '4' => 'author', |
||
181 | '5' => 'link', |
||
182 | '6' => 'field:handle', |
||
183 | ], |
||
184 | ], |
||
185 | ], |
||
186 | ], |
||
187 | 'Entry' => [ |
||
188 | 'sources' => [ |
||
189 | '*' => [ |
||
190 | 'tableAttributes' => [ |
||
191 | '1' => 'section', |
||
192 | '2' => 'postDate', |
||
193 | '3' => 'expiryDate', |
||
194 | '4' => 'author', |
||
195 | '5' => 'link', |
||
196 | ], |
||
197 | ], |
||
198 | ], |
||
199 | ], |
||
200 | ]; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * @return Mock|Sources |
||
205 | */ |
||
206 | private function setMockSources() |
||
220 | |||
221 | /** |
||
222 | * @param string $fieldType |
||
223 | * @param string $source |
||
224 | * @param string $fromIndex |
||
225 | * @param string $toIndex |
||
226 | * |
||
227 | * @return string |
||
228 | */ |
||
229 | public function getMockSourceCallback($fieldType, $source, $fromIndex, $toIndex) |
||
243 | |||
244 | /** |
||
245 | * @return Mock|CraftFieldsService |
||
246 | */ |
||
247 | private function setMockFieldsService() |
||
262 | } |
||
263 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.