|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
App::uses('ShellDispatcher', 'Console'); |
|
4
|
|
|
App::uses('ConsoleOutput', 'Console'); |
|
5
|
|
|
App::uses('ConsoleInput', 'Console'); |
|
6
|
|
|
App::uses('SeederTaskBase', 'FakeSeeder.Console'); |
|
7
|
|
|
App::uses('ShellSeedProcessor', 'FakeSeeder.Lib'); |
|
8
|
|
|
App::uses('ColumnTypeGuesser', 'FakeSeeder.Lib'); |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* ShellSeedProcessor Test |
|
12
|
|
|
* |
|
13
|
|
|
* @coversDefaultClass ShellSeedProcessor |
|
14
|
|
|
*/ |
|
15
|
|
|
class ShellSeedProcessorTest extends CakeTestCase { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The fixtures |
|
19
|
|
|
* |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
public $fixtures = array( |
|
23
|
|
|
'plugin.fake_seeder.apple', |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Disable auto loading the fixtures as we rarely need them |
|
28
|
|
|
* |
|
29
|
|
|
* @var bool |
|
30
|
|
|
*/ |
|
31
|
|
|
public $autoFixtures = false; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The shell object |
|
35
|
|
|
* |
|
36
|
|
|
* @var null|Shell |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $_seeder = null; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The object under test |
|
42
|
|
|
* |
|
43
|
|
|
* @var null|ShellSeedProcessor |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $_processor = null; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Setup the object under test |
|
49
|
|
|
* |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
|
|
public function setUp() { |
|
53
|
|
|
parent::setUp(); |
|
54
|
|
|
|
|
55
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false); |
|
56
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false); |
|
57
|
|
|
$this->_seeder = $this->getMock('SeederTaskBase', |
|
58
|
|
|
array(), |
|
59
|
|
|
array($out, $out, $in) |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Create a ShellSeedProcessor mock |
|
65
|
|
|
* |
|
66
|
|
|
* @param array $methods The methods to mock. |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function _createProcessorMock($methods) { |
|
70
|
|
|
$this->_processor = $this->getMock( |
|
71
|
|
|
'ShellSeedProcessor', |
|
72
|
|
|
$methods, |
|
73
|
|
|
array($this->_seeder) |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Test the constructor |
|
79
|
|
|
* |
|
80
|
|
|
* @return void |
|
81
|
|
|
* @covers ::__construct |
|
82
|
|
|
*/ |
|
83
|
|
|
public function testConstruct() { |
|
84
|
|
|
$processor = new ShellSeedProcessor($this->_seeder); |
|
|
|
|
|
|
85
|
|
|
$this->assertAttributeInstanceOf('SeederTaskBase', '_seeder', $processor); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Tests the processFixtures method |
|
90
|
|
|
* |
|
91
|
|
|
* @return void |
|
92
|
|
|
* @covers ::processFixtures |
|
93
|
|
|
*/ |
|
94
|
|
|
public function testProcessFixtures() { |
|
95
|
|
|
$this->_createProcessorMock(array('saveSeeds')); |
|
96
|
|
|
$fixtures = array(array('Model' => array('foo' => 'bar'))); |
|
97
|
|
|
|
|
98
|
|
|
$this->_seeder->expects($this->at(0))->method('fixtureRecords')->will($this->returnValue($fixtures)); |
|
99
|
|
|
$this->_processor->expects($this->at(0))->method('saveSeeds'); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
$this->_processor->processFixtures(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Tests the processFixtures method with no fixtures set |
|
106
|
|
|
* |
|
107
|
|
|
* @return void |
|
108
|
|
|
* @covers ::processFixtures |
|
109
|
|
|
*/ |
|
110
|
|
|
public function testProcessFixturesNoFixturesSet() { |
|
111
|
|
|
$this->_createProcessorMock(array('saveSeeds')); |
|
112
|
|
|
|
|
113
|
|
|
$fixtures = array(); |
|
114
|
|
|
|
|
115
|
|
|
$this->_seeder->expects($this->at(0))->method('fixtureRecords')->will($this->returnValue($fixtures)); |
|
116
|
|
|
$this->_processor->expects($this->never())->method('saveSeeds'); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
$this->_processor->processFixtures(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Tests the sowSeeds method when there are no field formatters |
|
123
|
|
|
* |
|
124
|
|
|
* @return void |
|
125
|
|
|
* @covers ::sowSeeds |
|
126
|
|
|
*/ |
|
127
|
|
|
public function testSowSeedsNoFieldFormatters() { |
|
128
|
|
|
$this->_createProcessorMock(array('getFieldFormatters', 'createSeed', 'saveSeeds')); |
|
129
|
|
|
|
|
130
|
|
|
$this->_seeder->expects($this->at(0))->method('getModelName')->will($this->returnValue('Apple')); |
|
131
|
|
|
$this->_seeder->expects($this->at(1))->method('getRecordsCount')->will($this->returnValue(5)); |
|
132
|
|
|
$this->_seeder->expects($this->at(2))->method('out')->with($this->equalTo('Sowing 5 seeds for model Apple')); |
|
133
|
|
|
$this->_seeder->expects($this->at(3))->method('out')->with($this->equalTo('No field formatters configured, aborting.')); |
|
134
|
|
|
|
|
135
|
|
|
$this->_processor->expects($this->at(0))->method('getFieldFormatters')->will($this->returnValue(array())); |
|
|
|
|
|
|
136
|
|
|
$this->_processor->expects($this->never())->method('createSeed'); |
|
|
|
|
|
|
137
|
|
|
$this->_processor->expects($this->never())->method('saveSeeds'); |
|
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
$this->_processor->sowSeeds(); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Tests the sowSeeds method when empty seeds get created |
|
144
|
|
|
* |
|
145
|
|
|
* @return void |
|
146
|
|
|
* @covers ::sowSeeds |
|
147
|
|
|
*/ |
|
148
|
|
|
public function testSowSeedsCreatedSeedEmpty() { |
|
149
|
|
|
$this->_createProcessorMock(array('getFieldFormatters', 'createSeed', 'saveSeeds')); |
|
150
|
|
|
|
|
151
|
|
|
$this->_seeder->expects($this->at(0))->method('getModelName')->will($this->returnValue('Apple')); |
|
152
|
|
|
$this->_seeder->expects($this->at(1))->method('getRecordsCount')->will($this->returnValue(5)); |
|
153
|
|
|
$this->_seeder->expects($this->at(2))->method('out')->with($this->equalTo('Sowing 5 seeds for model Apple')); |
|
154
|
|
|
$this->_seeder->expects($this->at(3))->method('out')->with($this->equalTo('Created seed is empty! Check the field formatters.')); |
|
155
|
|
|
$this->_seeder->expects($this->at(4))->method('out')->with($this->equalTo('Finished sowing 5 seeds for model Apple')); |
|
156
|
|
|
|
|
157
|
|
|
$this->_processor->expects($this->at(0))->method('getFieldFormatters')->will($this->returnValue(array('NotEmpty'))); |
|
|
|
|
|
|
158
|
|
|
$this->_processor->expects($this->at(1))->method('createSeed')->will($this->returnValue(array())); |
|
|
|
|
|
|
159
|
|
|
$this->_processor->expects($this->at(2))->method('saveSeeds'); |
|
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
$this->_processor->sowSeeds(); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Tests the sowSeeds method |
|
166
|
|
|
* |
|
167
|
|
|
* @return void |
|
168
|
|
|
* @covers ::sowSeeds |
|
169
|
|
|
*/ |
|
170
|
|
|
public function testSowSeeds() { |
|
171
|
|
|
$this->_createProcessorMock(array('getFieldFormatters', 'createSeed', 'saveSeeds')); |
|
172
|
|
|
|
|
173
|
|
|
$this->_seeder->expects($this->at(0))->method('getModelName')->will($this->returnValue('Apple')); |
|
174
|
|
|
$this->_seeder->expects($this->at(1))->method('getRecordsCount')->will($this->returnValue(5)); |
|
175
|
|
|
$this->_seeder->expects($this->at(2))->method('out')->with($this->equalTo('Sowing 5 seeds for model Apple')); |
|
176
|
|
|
$this->_seeder->expects($this->at(4))->method('out')->with($this->equalTo('.'), $this->equalTo(0)); |
|
177
|
|
|
$this->_seeder->expects($this->at(5))->method('out')->with($this->equalTo('.'), $this->equalTo(0)); |
|
178
|
|
|
$this->_seeder->expects($this->at(6))->method('out')->with($this->equalTo('.'), $this->equalTo(0)); |
|
179
|
|
|
$this->_seeder->expects($this->at(7))->method('out')->with($this->equalTo('.'), $this->equalTo(0)); |
|
180
|
|
|
$this->_seeder->expects($this->at(8))->method('out')->with($this->equalTo(' 5 / 5'), $this->equalTo(1)); |
|
181
|
|
|
$this->_seeder->expects($this->at(9))->method('out')->with($this->equalTo('Finished sowing 5 seeds for model Apple')); |
|
182
|
|
|
|
|
183
|
|
|
$this->_processor->expects($this->at(0))->method('getFieldFormatters')->will($this->returnValue(array('NotEmpty'))); |
|
|
|
|
|
|
184
|
|
|
$this->_processor->expects($this->exactly(5))->method('createSeed')->will($this->returnValue(array('NotEmpty'))); |
|
|
|
|
|
|
185
|
|
|
$this->_processor->expects($this->at(2))->method('saveSeeds'); |
|
|
|
|
|
|
186
|
|
|
|
|
187
|
|
|
$this->_processor->sowSeeds(); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Tests the sowSeeds method when sowing more than 50 seeds |
|
192
|
|
|
* |
|
193
|
|
|
* @return void |
|
194
|
|
|
* @covers ::sowSeeds |
|
195
|
|
|
*/ |
|
196
|
|
|
public function testSowSeedsFithyPlus() { |
|
197
|
|
|
$this->_createProcessorMock(array('getFieldFormatters', 'createSeed', 'saveSeeds')); |
|
198
|
|
|
|
|
199
|
|
|
$this->_seeder->expects($this->at(0))->method('getModelName')->will($this->returnValue('Apple')); |
|
200
|
|
|
$this->_seeder->expects($this->at(1))->method('getRecordsCount')->will($this->returnValue(55)); |
|
201
|
|
|
$this->_seeder->expects($this->at(3))->method('out')->with($this->equalTo('.'), $this->equalTo(0)); |
|
202
|
|
|
$this->_seeder->expects($this->at(53))->method('out')->with($this->equalTo(' 50 / 55'), $this->equalTo(1)); |
|
203
|
|
|
$this->_seeder->expects($this->at(58))->method('out')->with($this->equalTo('.'), $this->equalTo(0)); |
|
204
|
|
|
$this->_seeder->expects($this->at(59))->method('out')->with( |
|
205
|
|
|
$this->equalTo(str_repeat(' ', 46) . '55 / 55', 1) |
|
206
|
|
|
); |
|
207
|
|
|
|
|
208
|
|
|
$this->_processor->expects($this->at(0))->method('getFieldFormatters')->will($this->returnValue(array('NotEmpty'))); |
|
|
|
|
|
|
209
|
|
|
$this->_processor->expects($this->any())->method('createSeed')->will($this->returnValue(array('NotEmpty'))); |
|
|
|
|
|
|
210
|
|
|
$this->_processor->expects($this->at(2))->method('saveSeeds'); |
|
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
$this->_processor->sowSeeds(); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Tests the getFieldFormatters method for 'manual' mode |
|
217
|
|
|
* |
|
218
|
|
|
* @return void |
|
219
|
|
|
* @covers ::getFieldFormatters |
|
220
|
|
|
*/ |
|
221
|
|
View Code Duplication |
public function testGetFieldFormattersManualMode() { |
|
|
|
|
|
|
222
|
|
|
$this->_createProcessorMock(array('_guessFieldFormatters')); |
|
223
|
|
|
|
|
224
|
|
|
$expected = array('field formatters from manual mode'); |
|
225
|
|
|
|
|
226
|
|
|
$this->_seeder->expects($this->at(0))->method('getSeedingMode')->will($this->returnValue('manual')); |
|
227
|
|
|
$this->_seeder->expects($this->at(1))->method('fieldFormatters')->will($this->returnValue($expected)); |
|
228
|
|
|
$this->_processor->expects($this->never())->method('_guessFieldFormatters'); |
|
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
$result = $this->_processor->getFieldFormatters(); |
|
231
|
|
|
$this->assertEquals($expected, $result); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Tests the getFieldFormatters method for 'auto' mode |
|
236
|
|
|
* |
|
237
|
|
|
* @return void |
|
238
|
|
|
* @covers ::getFieldFormatters |
|
239
|
|
|
*/ |
|
240
|
|
View Code Duplication |
public function testGetFieldFormattersAutolMode() { |
|
|
|
|
|
|
241
|
|
|
$this->_createProcessorMock(array('_guessFieldFormatters')); |
|
242
|
|
|
|
|
243
|
|
|
$expected = array('field formatters from auto mode'); |
|
244
|
|
|
|
|
245
|
|
|
$this->_seeder->expects($this->at(0))->method('getSeedingMode')->will($this->returnValue('auto')); |
|
246
|
|
|
$this->_seeder->expects($this->never())->method('fieldFormatters'); |
|
247
|
|
|
$this->_processor->expects($this->at(0))->method('_guessFieldFormatters')->will($this->returnValue($expected)); |
|
|
|
|
|
|
248
|
|
|
|
|
249
|
|
|
$result = $this->_processor->getFieldFormatters(); |
|
250
|
|
|
$this->assertEquals($expected, $result); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Tests the getFieldFormatters method for 'mixed' mode |
|
255
|
|
|
* |
|
256
|
|
|
* @return void |
|
257
|
|
|
* @covers ::getFieldFormatters |
|
258
|
|
|
*/ |
|
259
|
|
|
public function testGetFieldFormattersMixedMode() { |
|
260
|
|
|
$this->_createProcessorMock(array('_guessFieldFormatters')); |
|
261
|
|
|
|
|
262
|
|
|
$manualMode = array('field formatters from manual mode'); |
|
263
|
|
|
$autoMode = array('field formatters from auto mode'); |
|
264
|
|
|
$expected = array_merge( |
|
265
|
|
|
$autoMode, |
|
266
|
|
|
$manualMode |
|
267
|
|
|
); |
|
268
|
|
|
|
|
269
|
|
|
$this->_seeder->expects($this->at(0))->method('getSeedingMode')->will($this->returnValue('mixed')); |
|
270
|
|
|
$this->_seeder->expects($this->once())->method('fieldFormatters')->will($this->returnValue($manualMode)); |
|
271
|
|
|
$this->_processor->expects($this->once())->method('_guessFieldFormatters')->will($this->returnValue($autoMode)); |
|
|
|
|
|
|
272
|
|
|
|
|
273
|
|
|
$result = $this->_processor->getFieldFormatters(); |
|
274
|
|
|
$this->assertEquals($expected, $result); |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* Tests the getFieldFormatters method for an invalid mode |
|
279
|
|
|
* |
|
280
|
|
|
* @return void |
|
281
|
|
|
* @covers ::getFieldFormatters |
|
282
|
|
|
*/ |
|
283
|
|
|
public function testGetFieldFormattersInvalidMode() { |
|
284
|
|
|
$this->_createProcessorMock(array('_guessFieldFormatters')); |
|
285
|
|
|
|
|
286
|
|
|
$this->_seeder->expects($this->at(0))->method('getSeedingMode')->will($this->returnValue('foo')); |
|
287
|
|
|
$this->_seeder->expects($this->never())->method('fieldFormatters'); |
|
288
|
|
|
$this->_processor->expects($this->never())->method('_guessFieldFormatters'); |
|
|
|
|
|
|
289
|
|
|
|
|
290
|
|
|
$result = $this->_processor->getFieldFormatters(); |
|
291
|
|
|
$this->assertEmpty($result); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* Tests the _guessFieldFormatters method |
|
296
|
|
|
* |
|
297
|
|
|
* @return void |
|
298
|
|
|
* @covers ::_guessFieldFormatters |
|
299
|
|
|
* @covers ::_getColumns |
|
300
|
|
|
*/ |
|
301
|
|
|
public function testGuessFieldFormatters() { |
|
302
|
|
|
$this->_createProcessorMock(array('_getModel', '_getColumnTypeGuesser')); |
|
303
|
|
|
|
|
304
|
|
|
$model = $this->getMock('Apple', array('schema')); |
|
305
|
|
|
$model->primaryKey = 'id'; |
|
306
|
|
|
|
|
307
|
|
|
$schema = array( |
|
308
|
|
|
'id' => array( |
|
309
|
|
|
'type' => 'integer', |
|
310
|
|
|
'null' => false, |
|
311
|
|
|
'default' => NULL, |
|
312
|
|
|
'length' => 11, |
|
313
|
|
|
'unsigned' => false, |
|
314
|
|
|
'key' => 'primary', |
|
315
|
|
|
), |
|
316
|
|
|
'field1' => array( |
|
317
|
|
|
'type' => 'string', |
|
318
|
|
|
'null' => false, |
|
319
|
|
|
'default' => NULL, |
|
320
|
|
|
'length' => 255, |
|
321
|
|
|
'collate' => 'latin1_swedish_ci', |
|
322
|
|
|
'charset' => 'latin1', |
|
323
|
|
|
), |
|
324
|
|
|
'field2' => array( |
|
325
|
|
|
'type' => 'datetime', |
|
326
|
|
|
'null' => true, |
|
327
|
|
|
'default' => NULL, |
|
328
|
|
|
'length' => NULL, |
|
329
|
|
|
), |
|
330
|
|
|
); |
|
331
|
|
|
|
|
332
|
|
|
$guesser = $this->getMock( |
|
333
|
|
|
'ColumnTypeGuesser', |
|
334
|
|
|
array(), |
|
335
|
|
|
array(), |
|
336
|
|
|
'', |
|
337
|
|
|
false |
|
338
|
|
|
); |
|
339
|
|
|
|
|
340
|
|
|
$guessedFormats = 'guessed formatter'; |
|
341
|
|
|
|
|
342
|
|
|
$this->_seeder->expects($this->at(0))->method('getSeedingMode')->will($this->returnValue('auto')); |
|
343
|
|
|
$this->_processor->expects($this->at(0))->method('_getModel')->will($this->returnValue($model)); |
|
|
|
|
|
|
344
|
|
|
$model->expects($this->at(0))->method('schema')->will($this->returnValue($schema)); |
|
345
|
|
|
$this->_processor->expects($this->at(1))->method('_getColumnTypeGuesser')->will($this->returnValue($guesser)); |
|
|
|
|
|
|
346
|
|
|
$guesser->expects($this->at(0))->method('guessFormat') |
|
347
|
|
|
->with($this->equalTo($schema['field1'])) |
|
348
|
|
|
->will($this->returnValue($guessedFormats)); |
|
349
|
|
|
$guesser->expects($this->at(1))->method('guessFormat') |
|
350
|
|
|
->with($this->equalTo($schema['field2'])) |
|
351
|
|
|
->will($this->returnValue($guessedFormats)); |
|
352
|
|
|
|
|
353
|
|
|
$result = $this->_processor->getFieldFormatters(); |
|
354
|
|
|
$expected = array( |
|
355
|
|
|
'field1' => $guessedFormats, |
|
356
|
|
|
'field2' => $guessedFormats, |
|
357
|
|
|
); |
|
358
|
|
|
$this->assertEquals($expected, $result); |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
/** |
|
362
|
|
|
* Tests the createSeed method |
|
363
|
|
|
* |
|
364
|
|
|
* @return void |
|
365
|
|
|
* @covers ::createSeed |
|
366
|
|
|
*/ |
|
367
|
|
|
public function testCreateSeed() { |
|
368
|
|
|
$this->_createProcessorMock(array('_getModel')); |
|
369
|
|
|
|
|
370
|
|
|
$this->_seeder->expects($this->at(0))->method('getModelName')->will($this->returnValue('ModelName')); |
|
371
|
|
|
$this->_seeder->expects($this->at(1))->method('recordState')->will($this->returnValue('state1')); |
|
372
|
|
|
|
|
373
|
|
|
$callable = function ($state) { |
|
374
|
|
|
return $state; |
|
375
|
|
|
}; |
|
376
|
|
|
|
|
377
|
|
|
$fieldFormatters = array( |
|
378
|
|
|
'field1' => $callable, |
|
379
|
|
|
'field2' => $callable, |
|
380
|
|
|
); |
|
381
|
|
|
$result = $this->_processor->createSeed($fieldFormatters); |
|
382
|
|
|
$expected = array( |
|
383
|
|
|
'ModelName' => array( |
|
384
|
|
|
'field1' => 'state1', |
|
385
|
|
|
'field2' => 'state1', |
|
386
|
|
|
), |
|
387
|
|
|
); |
|
388
|
|
|
$this->assertEquals($expected, $result); |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
/** |
|
392
|
|
|
* Tests the saveSeeds method when validate is 'false' |
|
393
|
|
|
* |
|
394
|
|
|
* @return void |
|
395
|
|
|
* @covers ::saveSeeds |
|
396
|
|
|
*/ |
|
397
|
|
View Code Duplication |
public function testSaveSeedsValidateFalse() { |
|
|
|
|
|
|
398
|
|
|
$this->_createProcessorMock(array('_getModel')); |
|
399
|
|
|
$seeds = array('seeds'); |
|
400
|
|
|
$model = $this->getMock('Apple', array('saveAll')); |
|
401
|
|
|
$options = array( |
|
402
|
|
|
'validate' => false |
|
403
|
|
|
); |
|
404
|
|
|
|
|
405
|
|
|
$this->_seeder->expects($this->at(0))->method('getValidateSeeding')->will($this->returnValue('false')); |
|
406
|
|
|
$this->_processor->expects($this->at(0))->method('_getModel')->will($this->returnValue($model)); |
|
|
|
|
|
|
407
|
|
|
$model->expects($this->at(0))->method('saveAll')->with( |
|
408
|
|
|
$this->equalTo($seeds), |
|
409
|
|
|
$this->equalTo($options) |
|
410
|
|
|
)->will($this->returnValue(true)); |
|
411
|
|
|
|
|
412
|
|
|
$this->_seeder->expects($this->never())->method('out'); |
|
413
|
|
|
|
|
414
|
|
|
$this->_processor->saveSeeds($seeds); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
/** |
|
418
|
|
|
* Tests the saveSeeds method when validate casts to true |
|
419
|
|
|
* |
|
420
|
|
|
* @return void |
|
421
|
|
|
* @covers ::saveSeeds |
|
422
|
|
|
*/ |
|
423
|
|
View Code Duplication |
public function testSaveSeedsValidateTrue() { |
|
|
|
|
|
|
424
|
|
|
$this->_createProcessorMock(array('_getModel')); |
|
425
|
|
|
$seeds = array('seeds'); |
|
426
|
|
|
$model = $this->getMock('Apple', array('saveAll')); |
|
427
|
|
|
$options = array( |
|
428
|
|
|
'validate' => true |
|
429
|
|
|
); |
|
430
|
|
|
|
|
431
|
|
|
$this->_seeder->expects($this->at(0))->method('getValidateSeeding')->will($this->returnValue('true')); |
|
432
|
|
|
$this->_processor->expects($this->at(0))->method('_getModel')->will($this->returnValue($model)); |
|
|
|
|
|
|
433
|
|
|
$model->expects($this->at(0))->method('saveAll')->with( |
|
434
|
|
|
$this->equalTo($seeds), |
|
435
|
|
|
$this->equalTo($options) |
|
436
|
|
|
)->will($this->returnValue(true)); |
|
437
|
|
|
|
|
438
|
|
|
$this->_seeder->expects($this->never())->method('out'); |
|
439
|
|
|
|
|
440
|
|
|
$this->_processor->saveSeeds($seeds); |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* Tests the saveSeeds method when saving fails |
|
445
|
|
|
* |
|
446
|
|
|
* @return void |
|
447
|
|
|
* @covers ::saveSeeds |
|
448
|
|
|
*/ |
|
449
|
|
|
public function testSaveSeedsNotSaved() { |
|
450
|
|
|
$this->_createProcessorMock(array('_getModel')); |
|
451
|
|
|
$seeds = array('seeds'); |
|
452
|
|
|
$model = $this->getMock('Apple', array('saveAll')); |
|
453
|
|
|
$options = array( |
|
454
|
|
|
'validate' => 'first' |
|
455
|
|
|
); |
|
456
|
|
|
|
|
457
|
|
|
$model->validationErrors = 'test123'; |
|
458
|
|
|
|
|
459
|
|
|
$this->_seeder->expects($this->at(0))->method('getValidateSeeding')->will($this->returnValue('first')); |
|
460
|
|
|
$this->_processor->expects($this->at(0))->method('_getModel')->will($this->returnValue($model)); |
|
|
|
|
|
|
461
|
|
|
|
|
462
|
|
|
$model->expects($this->at(0))->method('saveAll')->with( |
|
463
|
|
|
$this->equalTo($seeds), |
|
464
|
|
|
$this->equalTo($options) |
|
465
|
|
|
)->will($this->returnValue(false)); |
|
466
|
|
|
|
|
467
|
|
|
$this->_seeder->expects($this->at(1))->method('out')->with($this->equalTo('Seeds could not be saved successfully!')); |
|
468
|
|
|
$this->_seeder->expects($this->at(2))->method('out')->with($this->equalTo("Data validation errors: 'test123'")); |
|
469
|
|
|
|
|
470
|
|
|
$this->_processor->saveSeeds($seeds); |
|
471
|
|
|
} |
|
472
|
|
|
} |
|
473
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: