Conditions | 1 |
Total Lines | 111 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
253 | public function testBeforeManyToMany() |
||
254 | { |
||
255 | $spec = [ |
||
256 | [ |
||
257 | 'name' => 'id', |
||
258 | 'type' => 'integer', |
||
259 | 'nullable' => false, |
||
260 | ], |
||
261 | [ |
||
262 | 'name' => 'name', |
||
263 | 'type' => 'string', |
||
264 | 'nullable' => false, |
||
265 | ], |
||
266 | [ |
||
267 | 'name' => 'email', |
||
268 | 'type' => 'string', |
||
269 | 'nullable' => false, |
||
270 | ], |
||
271 | [ |
||
272 | 'name' => 'groups', |
||
273 | 'type' => 'manytomany', |
||
274 | 'entity' => 'Dummy\\Group', |
||
275 | 'nullable' => false, |
||
276 | ], |
||
277 | ]; |
||
278 | $provider1 = $this->providers[0]; |
||
279 | $provider1->getEntitySpec()->willReturn($spec); |
||
280 | $provider1->getPostParams()->willReturn([ |
||
281 | 'name' => 'Bob', |
||
282 | 'email' => '[email protected]', |
||
283 | 'groups' => [1], |
||
284 | ]); |
||
285 | |||
286 | $provider3 = $this->getUserProvider(2, $spec, [ |
||
287 | 'name' => 'Joe', |
||
288 | 'email' => '[email protected]', |
||
289 | 'groups' => "1,2", |
||
290 | ], [ |
||
291 | 'id' => 2, |
||
292 | 'name' => 'Joe', |
||
293 | 'email' => '[email protected]', |
||
294 | ]); |
||
295 | $this->providers[] = $provider3; |
||
296 | |||
297 | $provider4 = $this->getGroupProvider(2, [ |
||
298 | [ |
||
299 | 'name' => 'id', |
||
300 | 'type' => 'integer', |
||
301 | 'nullable' => false, |
||
302 | ], |
||
303 | [ |
||
304 | 'name' => 'name', |
||
305 | 'type' => 'string', |
||
306 | 'nullable' => false, |
||
307 | ], |
||
308 | ], [ |
||
309 | 'name' => 'Special', |
||
310 | ], [ |
||
311 | 'id' => 2, |
||
312 | 'name' => 'Special', |
||
313 | ]); |
||
314 | $this->providers[] = $provider4; |
||
315 | |||
316 | $actual = (new class('Dummy\\User', $this->getFactory(), 2) extends AbstractTest |
||
317 | { |
||
318 | /** |
||
319 | * @var int |
||
320 | */ |
||
321 | private $times; |
||
322 | |||
323 | public function __construct( |
||
324 | string $entityClassName, |
||
325 | EntityProviderFactoryInterface $entityProviderFactory, |
||
326 | int $times |
||
327 | ) { |
||
328 | parent::__construct($entityClassName, $entityProviderFactory); |
||
329 | $this->times = $times; |
||
330 | } |
||
331 | |||
332 | public function generate(): string |
||
333 | { |
||
334 | return $this->generateHaveInRepo($this->times); |
||
335 | } |
||
336 | |||
337 | public function getClassName(): string |
||
338 | { |
||
339 | return 'TestCest'; |
||
340 | } |
||
341 | })->generate(); |
||
342 | |||
343 | $expected = <<<'BODY' |
||
344 | $I->haveInRepository('Dummy\Group', array ( |
||
345 | 'id' => 1, |
||
346 | 'name' => 'Default', |
||
347 | )); |
||
348 | $group = $I->grabEntityFromRepository('Dummy\Group', ['id' => 1]); |
||
349 | $I->haveInRepository('Dummy\User', array ( |
||
350 | 'id' => 1, |
||
351 | 'name' => 'Bob', |
||
352 | 'email' => '[email protected]', |
||
353 | 'groups' => [$group], |
||
354 | )); |
||
355 | $I->haveInRepository('Dummy\User', array ( |
||
356 | 'id' => 2, |
||
357 | 'name' => 'Joe', |
||
358 | 'email' => '[email protected]', |
||
359 | 'groups' => [$group], |
||
360 | )); |
||
361 | |||
362 | BODY; |
||
363 | $this->assertEquals($expected, $actual); |
||
364 | } |
||
366 |