This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | App::uses('SeederTaskBase', 'FakeSeeder.Console'); |
||
4 | App::uses('ConsoleOutput', 'Console'); |
||
5 | App::uses('ConsoleInput', 'Console'); |
||
6 | App::uses('ShellSeedProcessor', 'FakeSeeder.Lib'); |
||
7 | |||
8 | /** |
||
9 | * A testable implementation of SeederTaskBase |
||
10 | */ |
||
11 | class TestSeederTaskBase extends SeederTaskBase { |
||
12 | |||
13 | /** |
||
14 | * A test proxy method for _mergeFieldFormatters |
||
15 | */ |
||
16 | public function mergeFieldFormatters($fieldFormatters) { |
||
17 | return $this->_mergeFieldFormatters($fieldFormatters); |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * A test proxy method for _getParameter |
||
22 | */ |
||
23 | public function getParameter($configKey, $propertyName, $defaultValue = null) { |
||
24 | return parent::_getParameter($configKey, $propertyName, $defaultValue); |
||
0 ignored issues
–
show
|
|||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Needs to be implemented |
||
29 | */ |
||
30 | public function fieldFormatters() { |
||
31 | $this->_fieldFormatters; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * A test proxy method for _getSeederConfigKey |
||
36 | */ |
||
37 | public function getSeederConfigKey() { |
||
38 | return $this->_getSeederConfigKey(); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * A test proxy method for _getSeederNamePrefix |
||
43 | */ |
||
44 | public function getSeederNamePrefix() { |
||
45 | return $this->_getSeederNamePrefix(); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * A test proxy method for _getSeederShellName |
||
50 | */ |
||
51 | public function getSeederShellName() { |
||
52 | return $this->_getSeederShellName(); |
||
53 | } |
||
54 | |||
55 | } |
||
56 | |||
57 | /** |
||
58 | * A testable implementation of SeederTaskBase with all proprties set |
||
59 | */ |
||
60 | class PropertiesSetSeederTaskBase extends TestSeederTaskBase { |
||
61 | |||
62 | /** |
||
63 | * The config key to read, 'FakeSeeder.$_configKey.valueKey' |
||
64 | * |
||
65 | * Does not need to be set, uses the name of the seeder class by default, e.g. "Article" for "ArticleSeederShell". |
||
66 | * |
||
67 | * @var string |
||
68 | */ |
||
69 | protected $_configKey = 'CustomConfigKey'; |
||
70 | |||
71 | /** |
||
72 | * The name of the model to seed |
||
73 | * |
||
74 | * Does not need to be set, uses the name of the seeder class by default, e.g. "Article" for "ArticleSeederTask". |
||
75 | * |
||
76 | * @var string |
||
77 | */ |
||
78 | protected $_modelName = 'CustomModelName'; |
||
79 | |||
80 | /** |
||
81 | * Models to truncate |
||
82 | * |
||
83 | * Does not need to be set, uses the name of the seeder class by default, e.g. "Article" for "ArticleSeederTask". |
||
84 | * |
||
85 | * @var array |
||
86 | */ |
||
87 | protected $_modelsToTruncate = array('AnotherModel'); |
||
88 | |||
89 | /** |
||
90 | * Fixture records which are processed additionally and before the faked ones |
||
91 | * |
||
92 | * @var array |
||
93 | */ |
||
94 | protected $_fixtureRecords = array(array('foo' => 'bar')); |
||
95 | |||
96 | /** |
||
97 | * The fields and their formatter |
||
98 | * |
||
99 | * @var array |
||
100 | */ |
||
101 | protected $_fieldFormatters = array(); |
||
102 | |||
103 | /** |
||
104 | * The seeding mode, optional. |
||
105 | * |
||
106 | * @var null|string |
||
107 | */ |
||
108 | protected $_mode = 'mixed'; |
||
109 | |||
110 | /** |
||
111 | * The locale to use for Faker, optional |
||
112 | * |
||
113 | * @var null|int |
||
114 | */ |
||
115 | protected $_locale = 'de_DE'; |
||
116 | |||
117 | /** |
||
118 | * Set the minimum record count for a seeder task, null means no minimum. |
||
119 | * |
||
120 | * @var null|int |
||
121 | */ |
||
122 | protected $_minRecords = 5; |
||
123 | |||
124 | /** |
||
125 | * Set the maximum record count for a seeder task, null means no maximum. |
||
126 | * |
||
127 | * @var null|int |
||
128 | */ |
||
129 | protected $_maxRecords = 100; |
||
130 | |||
131 | /** |
||
132 | * The records to seed, optional |
||
133 | * |
||
134 | * @var null|int |
||
135 | */ |
||
136 | protected $_records = 50; |
||
137 | |||
138 | /** |
||
139 | * Whether or not to validate the seeding data when saving, optional |
||
140 | * |
||
141 | * @var null|bool|string |
||
142 | * @see Model::saveAll() See for possible values for `validate`. |
||
143 | */ |
||
144 | protected $_validateSeeding = false; |
||
145 | |||
146 | /** |
||
147 | * The seeding number for Faker to use |
||
148 | * |
||
149 | * @var null|bool|int |
||
150 | * @see Generator::seed Faker's seed method. |
||
151 | */ |
||
152 | protected $_seedingNumber = 123456789; |
||
153 | |||
154 | /** |
||
155 | * Whether or not to truncate the model , optional. |
||
156 | * |
||
157 | * @var null|bool |
||
158 | */ |
||
159 | protected $_noTruncate = true; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * SeederTaskBase Test |
||
164 | * |
||
165 | * @coversDefaultClass SeederTaskBase |
||
166 | */ |
||
167 | class SeederTaskBaseTest extends CakeTestCase { |
||
168 | |||
169 | /** |
||
170 | * The task under test |
||
171 | * |
||
172 | * @var null|TestSeederTaskBase |
||
173 | */ |
||
174 | protected $_task = null; |
||
175 | |||
176 | /** |
||
177 | * Setup the shell under test |
||
178 | * |
||
179 | * @return void |
||
180 | */ |
||
181 | View Code Duplication | public function setUp() { |
|
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. ![]() |
|||
182 | parent::setUp(); |
||
183 | |||
184 | $this->_createShellMock( |
||
185 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getParameter') |
||
186 | ); |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Creates a shell mock |
||
191 | * |
||
192 | * @param array $methods A list of methods to mock. |
||
193 | * @param string $className Optional name of the seeder shell class to mock. |
||
194 | * @return void |
||
195 | */ |
||
196 | View Code Duplication | protected function _createShellMock($methods, $className = 'TestSeederTaskBase') { |
|
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. ![]() |
|||
197 | $out = $this->getMock('ConsoleOutput', array(), array(), '', false); |
||
198 | $in = $this->getMock('ConsoleInput', array(), array(), '', false); |
||
199 | $this->_task = $this->getMock( |
||
200 | $className, |
||
201 | $methods, |
||
202 | array($out, $out, $in) |
||
203 | ); |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * Tests the execute method |
||
208 | * |
||
209 | * @return void |
||
210 | * @covers ::execute |
||
211 | * @covers ::_getFaker |
||
212 | * @covers ::_truncateModels |
||
213 | */ |
||
214 | public function testExecute() { |
||
215 | $this->_createShellMock( |
||
216 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', 'getLocale', 'getSeedingNumber', 'getNoTruncate', 'getModelsToTruncate', '_getModelTruncator', '_getSeedProcessor') |
||
217 | ); |
||
218 | $seedProcessor = $this->getMock( |
||
219 | 'ShellSeedProcessor', |
||
220 | array('processFixtures', 'sowSeeds'), |
||
221 | array(), |
||
222 | '', |
||
223 | false |
||
224 | ); |
||
225 | $modelTruncator = $this->getMock( |
||
226 | 'ShellModelTruncator', |
||
227 | array('truncateModels'), |
||
228 | array(), |
||
229 | '', |
||
230 | false |
||
231 | ); |
||
232 | $modelsToTruncate = array('Apple', 'Banana'); |
||
233 | |||
234 | $this->_task->expects($this->at(0))->method('getLocale')->will($this->returnValue('de_DE')); |
||
235 | $this->_task->expects($this->at(1))->method('getSeedingNumber')->will($this->returnValue(123456)); |
||
236 | $this->_task->expects($this->at(2))->method('out')->with($this->equalTo('Create Faker instance with "de_DE" locale...')); |
||
237 | $this->_task->expects($this->at(3))->method('out')->with($this->equalTo("Use seed '123456' for Faker.")); |
||
238 | $this->_task->expects($this->at(4))->method('getNoTruncate')->will($this->returnValue(false)); |
||
239 | $this->_task->expects($this->at(5))->method('getModelsToTruncate')->will($this->returnValue($modelsToTruncate)); |
||
240 | $this->_task->expects($this->at(6))->method('_getModelTruncator')->will($this->returnValue($modelTruncator)); |
||
241 | $this->_task->expects($this->at(7))->method('_getSeedProcessor')->will($this->returnValue($seedProcessor)); |
||
242 | |||
243 | $modelTruncator->expects($this->at(0))->method('truncateModels')->with($this->equalTo($modelsToTruncate)); |
||
244 | |||
245 | $seedProcessor->expects($this->at(0))->method('processFixtures'); |
||
246 | $seedProcessor->expects($this->at(1))->method('sowSeeds'); |
||
247 | |||
248 | $this->_task->execute(); |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * Tests the getModelsToTruncate method |
||
253 | * |
||
254 | * @return void |
||
255 | * @covers ::getModelsToTruncate |
||
256 | */ |
||
257 | View Code Duplication | public function testGetModelsToTruncate() { |
|
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. ![]() |
|||
258 | $this->_createShellMock( |
||
259 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', 'getModelName') |
||
260 | ); |
||
261 | $expected = array('YetAnotherModel'); |
||
262 | $this->_task->expects($this->at(0))->method('getModelName')->will($this->returnValue('YetAnotherModel')); |
||
263 | |||
264 | $result = $this->_task->getModelsToTruncate(); |
||
265 | |||
266 | $this->assertEquals($expected, $result); |
||
267 | } |
||
268 | |||
269 | /** |
||
270 | * Tests the fixtureRecords method |
||
271 | * |
||
272 | * @return void |
||
273 | * @covers ::getModelsToTruncate |
||
274 | */ |
||
275 | View Code Duplication | public function testGetModelsToTruncatePropertySet() { |
|
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. ![]() |
|||
276 | $this->_createShellMock( |
||
277 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getParameter'), |
||
278 | 'PropertiesSetSeederTaskBase' |
||
279 | ); |
||
280 | |||
281 | $result = $this->_task->getModelsToTruncate(); |
||
282 | $expected = array('AnotherModel'); |
||
283 | |||
284 | $this->assertEquals($expected, $result); |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * Tests the getModelsToTruncate method |
||
289 | * |
||
290 | * @return void |
||
291 | * @covers ::fixtureRecords |
||
292 | */ |
||
293 | View Code Duplication | public function testFixtureRecords() { |
|
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. ![]() |
|||
294 | $this->_createShellMock( |
||
295 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getParameter'), |
||
296 | 'PropertiesSetSeederTaskBase' |
||
297 | ); |
||
298 | |||
299 | $result = $this->_task->fixtureRecords(); |
||
300 | $expected = array(array('foo' => 'bar')); |
||
301 | |||
302 | $this->assertEquals($expected, $result); |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * Tests the _mergeFieldFormatters method |
||
307 | * |
||
308 | * @return void |
||
309 | * @covers ::_mergeFieldFormatters |
||
310 | */ |
||
311 | public function testMergeFieldFormatters() { |
||
312 | $result = $this->_task->mergeFieldFormatters(array()); |
||
313 | $this->assertEmpty($result); |
||
314 | |||
315 | $fieldFormatters = array('foo'); |
||
316 | $result = $this->_task->mergeFieldFormatters($fieldFormatters); |
||
317 | $this->assertEquals($fieldFormatters, $result); |
||
318 | |||
319 | $fieldFormatters = array('bar'); |
||
320 | $result = $this->_task->mergeFieldFormatters($fieldFormatters); |
||
321 | $expected = array('foo', 'bar'); |
||
322 | $this->assertEquals($expected, $result); |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * Tests the recordState method |
||
327 | * |
||
328 | * @return void |
||
329 | * @covers ::recordState |
||
330 | */ |
||
331 | public function testRecordsState() { |
||
332 | $result = $this->_task->recordState(); |
||
333 | $expected = array(); |
||
334 | |||
335 | $this->assertEquals($expected, $result); |
||
336 | } |
||
337 | |||
338 | /** |
||
339 | * Tests the getModelName method |
||
340 | * |
||
341 | * @return void |
||
342 | * @covers ::getModelName |
||
343 | */ |
||
344 | View Code Duplication | public function testGetModelName() { |
|
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. ![]() |
|||
345 | $this->_createShellMock( |
||
346 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getSeederNamePrefix') |
||
347 | ); |
||
348 | $expected = 'AModelName'; |
||
349 | $this->_task->expects($this->at(0))->method('_getSeederNamePrefix')->will($this->returnValue($expected)); |
||
350 | $result = $this->_task->getModelName(); |
||
351 | $this->assertEquals($expected, $result); |
||
352 | } |
||
353 | |||
354 | /** |
||
355 | * Tests the getModelName method |
||
356 | * |
||
357 | * @return void |
||
358 | * @covers ::getModelName |
||
359 | */ |
||
360 | View Code Duplication | public function testGetModelNamePropertySet() { |
|
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. ![]() |
|||
361 | $this->_createShellMock( |
||
362 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell'), |
||
363 | 'PropertiesSetSeederTaskBase' |
||
364 | ); |
||
365 | $expected = 'CustomModelName'; |
||
366 | $result = $this->_task->getModelName(); |
||
367 | $this->assertEquals($expected, $result); |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * Tests the getSeedingMode method |
||
372 | * |
||
373 | * @return void |
||
374 | * @covers ::getSeedingMode |
||
375 | */ |
||
376 | View Code Duplication | public function testGetSeedingMode() { |
|
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. ![]() |
|||
377 | $value = 'auto'; |
||
378 | $this->_task->expects($this->at(0))->method('_getParameter')->will($this->returnValue($value)); |
||
379 | $result = $this->_task->getSeedingMode(); |
||
380 | $this->assertEquals($value, $result); |
||
381 | } |
||
382 | |||
383 | /** |
||
384 | * Tests the getSeedingMode method |
||
385 | * |
||
386 | * @return void |
||
387 | * @covers ::getLocale |
||
388 | */ |
||
389 | View Code Duplication | public function testGetLocale() { |
|
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. ![]() |
|||
390 | $value = 'de_DE'; |
||
391 | $this->_task->expects($this->at(0))->method('_getParameter')->will($this->returnValue($value)); |
||
392 | $result = $this->_task->getLocale(); |
||
393 | $this->assertEquals($value, $result); |
||
394 | } |
||
395 | |||
396 | /** |
||
397 | * Tests the getRecordsCount method |
||
398 | * |
||
399 | * @return void |
||
400 | * @covers ::getRecordsCount |
||
401 | * @covers ::_enforceRecordMaximum |
||
402 | * @covers ::_enforceRecordMinimum |
||
403 | */ |
||
404 | public function testGetRecordsCount() { |
||
405 | $value = '50'; |
||
406 | $this->_task->expects($this->at(0))->method('_getParameter')->will($this->returnValue($value)); |
||
407 | $this->_task->expects($this->never())->method('out'); |
||
408 | $result = $this->_task->getRecordsCount(); |
||
409 | $this->assertEquals($value, $result); |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * Tests the getRecordsCount method when records is set too high |
||
414 | * |
||
415 | * @return void |
||
416 | * @covers ::getRecordsCount |
||
417 | * @covers ::_enforceRecordMaximum |
||
418 | */ |
||
419 | View Code Duplication | public function testGetRecordsCountTooHigh() { |
|
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. ![]() |
|||
420 | $this->_createShellMock( |
||
421 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getParameter'), |
||
422 | 'PropertiesSetSeederTaskBase' |
||
423 | ); |
||
424 | |||
425 | $value = '500'; |
||
426 | $this->_task->expects($this->at(0))->method('_getParameter')->will($this->returnValue($value)); |
||
427 | $this->_task->expects($this->at(1))->method('out')->with($this->equalTo('500 records exceed the allowed maximum amount. Reducing it to 100 records.')); |
||
428 | $result = $this->_task->getRecordsCount(); |
||
429 | |||
430 | $this->assertEquals(100, $result); |
||
431 | } |
||
432 | |||
433 | /** |
||
434 | * Tests the getRecordsCount method when records is set too low |
||
435 | * |
||
436 | * @return void |
||
437 | * @covers ::getRecordsCount |
||
438 | * @covers ::_enforceRecordMinimum |
||
439 | */ |
||
440 | View Code Duplication | public function testGetRecordsCountTooLow() { |
|
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. ![]() |
|||
441 | $this->_createShellMock( |
||
442 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getParameter'), |
||
443 | 'PropertiesSetSeederTaskBase' |
||
444 | ); |
||
445 | |||
446 | $value = '1'; |
||
447 | $this->_task->expects($this->at(0))->method('_getParameter')->will($this->returnValue($value)); |
||
448 | $this->_task->expects($this->at(1))->method('out')->with($this->equalTo('1 records fall below the allowed minimum amount. Increasing it to 5 records.')); |
||
449 | $result = $this->_task->getRecordsCount(); |
||
450 | |||
451 | $this->assertEquals(5, $result); |
||
452 | } |
||
453 | |||
454 | /** |
||
455 | * Tests the getValidateSeeding method |
||
456 | * |
||
457 | * @return void |
||
458 | * @covers ::getValidateSeeding |
||
459 | */ |
||
460 | View Code Duplication | public function testGetValidateSeeding() { |
|
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. ![]() |
|||
461 | $value = 'first'; |
||
462 | $this->_task->expects($this->at(0))->method('_getParameter')->will($this->returnValue($value)); |
||
463 | $result = $this->_task->getValidateSeeding(); |
||
464 | $this->assertEquals($value, $result); |
||
465 | } |
||
466 | |||
467 | /** |
||
468 | * Tests the getSeedingNumber method |
||
469 | * |
||
470 | * @return void |
||
471 | * @covers ::getSeedingNumber |
||
472 | */ |
||
473 | View Code Duplication | public function testGetSeedingNumber() { |
|
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. ![]() |
|||
474 | $value = '123456'; |
||
475 | $this->_task->expects($this->at(0))->method('_getParameter')->will($this->returnValue($value)); |
||
476 | $result = $this->_task->getSeedingNumber(); |
||
477 | $this->assertEquals($value, $result); |
||
478 | } |
||
479 | |||
480 | /** |
||
481 | * Tests the getNoTruncate method |
||
482 | * |
||
483 | * @return void |
||
484 | * @covers ::getNoTruncate |
||
485 | */ |
||
486 | View Code Duplication | public function testGetNoTruncate() { |
|
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. ![]() |
|||
487 | $value = true; |
||
488 | $this->_task->expects($this->at(0))->method('_getParameter')->will($this->returnValue($value)); |
||
489 | $result = $this->_task->getNoTruncate(); |
||
490 | $this->assertEquals($value, $result); |
||
491 | } |
||
492 | |||
493 | /** |
||
494 | * Tests the _getParameter method for the default value |
||
495 | * |
||
496 | * @return void |
||
497 | * @covers ::_getParameter |
||
498 | */ |
||
499 | public function testGetParameterDefaultValue() { |
||
500 | $this->_createShellMock( |
||
501 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getSeederTasks') |
||
502 | ); |
||
503 | |||
504 | $this->_task->expects($this->at(0))->method('out')->with($this->equalTo('Parameter "records" not given/configured, falling back to default "500".')); |
||
505 | |||
506 | $configKey = 'records'; |
||
507 | $propertyName = '_records'; |
||
508 | $defaultValue = '500'; |
||
509 | |||
510 | $this->_task->params[$configKey] = null; |
||
511 | Configure::write('FakeSeeder.TestSeederTaskBase.' . $configKey, null); |
||
512 | Configure::write('FakeSeeder.' . $configKey, null); |
||
513 | |||
514 | $result = $this->_task->getParameter($configKey, $propertyName, $defaultValue); |
||
515 | $this->assertEquals($defaultValue, $result); |
||
516 | } |
||
517 | |||
518 | /** |
||
519 | * Tests the _getParameter method when the property is set |
||
520 | * |
||
521 | * @return void |
||
522 | * @covers ::_getParameter |
||
523 | */ |
||
524 | View Code Duplication | public function testGetParameterPropertySet() { |
|
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. ![]() |
|||
525 | $this->_createShellMock( |
||
526 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getSeederTasks') |
||
527 | ); |
||
528 | |||
529 | $this->_createShellMock(array('out'), 'PropertiesSetSeederTaskBase'); |
||
530 | |||
531 | $this->_task->expects($this->at(0))->method('out')->with($this->equalTo('Parameter "records" set in class: "50"')); |
||
532 | |||
533 | $configKey = 'records'; |
||
534 | $propertyName = '_records'; |
||
535 | |||
536 | $this->_task->params[$configKey] = null; |
||
537 | Configure::write('FakeSeeder.TestSeederTaskBase.' . $configKey, null); |
||
538 | Configure::write('FakeSeeder.' . $configKey, null); |
||
539 | |||
540 | $result = $this->_task->getParameter($configKey, $propertyName); |
||
541 | $this->assertEquals(50, $result); |
||
542 | } |
||
543 | |||
544 | /** |
||
545 | * Tests the _getParameter method when the general config is set |
||
546 | * |
||
547 | * @return void |
||
548 | * @covers ::_getParameter |
||
549 | */ |
||
550 | View Code Duplication | public function testGetParameterGeneralConfgigSet() { |
|
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. ![]() |
|||
551 | $this->_createShellMock( |
||
552 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getSeederTasks') |
||
553 | ); |
||
554 | |||
555 | $this->_task->expects($this->at(0))->method('out')->with($this->equalTo('Parameter "records" configured in general seeder configuration: "75"')); |
||
556 | |||
557 | $configKey = 'records'; |
||
558 | $propertyName = '_records'; |
||
559 | |||
560 | $this->_task->params[$configKey] = null; |
||
561 | Configure::write('FakeSeeder.TestSeederTaskBase.' . $configKey, null); |
||
562 | Configure::write('FakeSeeder.' . $configKey, 75); |
||
563 | |||
564 | $result = $this->_task->getParameter($configKey, $propertyName); |
||
565 | $this->assertEquals(75, $result); |
||
566 | } |
||
567 | |||
568 | /** |
||
569 | * Tests the _getParameter method when the seeder specific config is set |
||
570 | * |
||
571 | * @return void |
||
572 | * @covers ::_getParameter |
||
573 | */ |
||
574 | public function testGetParameterSeederConfgigSet() { |
||
575 | $this->_createShellMock( |
||
576 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getSeederTasks') |
||
577 | ); |
||
578 | |||
579 | $this->_createShellMock(array('out', '_getSeederConfigKey')); |
||
580 | |||
581 | $this->_task->expects($this->at(0))->method('_getSeederConfigKey')->will($this->returnValue('FakeSeeder.TestSeederTaskBase')); |
||
582 | $this->_task->expects($this->at(1))->method('out')->with($this->equalTo('Parameter "records" configured in seeder specific configuration: "62"')); |
||
583 | |||
584 | $configKey = 'records'; |
||
585 | $propertyName = '_records'; |
||
586 | |||
587 | $this->_task->params[$configKey] = null; |
||
588 | Configure::write('FakeSeeder.TestSeederTaskBase.' . $configKey, 62); |
||
589 | Configure::write('FakeSeeder.' . $configKey, null); |
||
590 | |||
591 | $result = $this->_task->getParameter($configKey, $propertyName); |
||
592 | $this->assertEquals(62, $result); |
||
593 | } |
||
594 | |||
595 | /** |
||
596 | * Tests the _getParameter method when the parameter is set |
||
597 | * |
||
598 | * @return void |
||
599 | * @covers ::_getParameter |
||
600 | */ |
||
601 | View Code Duplication | public function testGetParameterParameterSet() { |
|
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. ![]() |
|||
602 | $this->_createShellMock( |
||
603 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getSeederTasks') |
||
604 | ); |
||
605 | |||
606 | $this->_task->expects($this->at(0))->method('out')->with($this->equalTo('Parameter "records" given through CLI parameter: "24"')); |
||
607 | |||
608 | $configKey = 'records'; |
||
609 | $propertyName = '_records'; |
||
610 | |||
611 | $this->_task->params[$configKey] = 24; |
||
612 | Configure::write('FakeSeeder.TestSeederTaskBase.' . $configKey, null); |
||
613 | Configure::write('FakeSeeder.' . $configKey, null); |
||
614 | |||
615 | $result = $this->_task->getParameter($configKey, $propertyName); |
||
616 | $this->assertEquals(24, $result); |
||
617 | } |
||
618 | |||
619 | /** |
||
620 | * Tests the _getSeederConfigKey method |
||
621 | * |
||
622 | * @return void |
||
623 | * @covers ::_getSeederConfigKey |
||
624 | */ |
||
625 | View Code Duplication | public function testGetSeederConfigKey() { |
|
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. ![]() |
|||
626 | $this->_createShellMock( |
||
627 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getSeederShellName', '_getSeederNamePrefix') |
||
628 | ); |
||
629 | $this->_task->expects($this->at(0))->method('_getSeederNamePrefix')->will($this->returnValue('TaskName')); |
||
630 | $this->_task->expects($this->at(1))->method('_getSeederShellName')->will($this->returnValue('FakeSeeder')); |
||
631 | $expected = 'FakeSeeder.TaskName'; |
||
632 | $result = $this->_task->getSeederConfigKey(); |
||
633 | $this->assertEquals($expected, $result); |
||
634 | } |
||
635 | |||
636 | /** |
||
637 | * Tests the _getSeederConfigKey method |
||
638 | * |
||
639 | * @return void |
||
640 | * @covers ::_getSeederConfigKey |
||
641 | */ |
||
642 | View Code Duplication | public function testGetSeederConfigKeyPropertySet() { |
|
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. ![]() |
|||
643 | $this->_createShellMock( |
||
644 | array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getSeederShellName'), |
||
645 | 'PropertiesSetSeederTaskBase' |
||
646 | ); |
||
647 | $this->_task->expects($this->at(0))->method('_getSeederShellName')->will($this->returnValue('FakeSeeder')); |
||
648 | $expected = 'FakeSeeder.CustomConfigKey'; |
||
649 | $result = $this->_task->getSeederConfigKey(); |
||
650 | $this->assertEquals($expected, $result); |
||
651 | } |
||
652 | |||
653 | /** |
||
654 | * Tests the _getSeederNamePrefix method |
||
655 | * |
||
656 | * @return void |
||
657 | * @covers ::_getSeederNamePrefix |
||
658 | */ |
||
659 | public function testGetSeederNamePrefix() { |
||
660 | $out = $this->getMock('ConsoleOutput', array(), array(), '', false); |
||
661 | $in = $this->getMock('ConsoleInput', array(), array(), '', false); |
||
662 | $this->_task = $this->getMock( |
||
663 | 'TestSeederTaskBase', |
||
664 | null, |
||
665 | array($out, $out, $in), |
||
666 | 'TestNameSeederTask', |
||
667 | false |
||
668 | ); |
||
669 | |||
670 | $expected = 'TestName'; |
||
671 | $result = $this->_task->getSeederNamePrefix(); |
||
672 | $this->assertEquals($expected, $result); |
||
673 | } |
||
674 | |||
675 | /** |
||
676 | * Tests the _getSeederShellName method |
||
677 | * |
||
678 | * @return void |
||
679 | * @covers ::_getSeederShellName |
||
680 | */ |
||
681 | public function testGetSeederShellName() { |
||
682 | $this->assertEquals('FakeSeeder', $this->_task->getSeederShellName()); |
||
683 | } |
||
684 | } |
||
685 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.