@@ -271,28 +271,59 @@ public function testVerifyOnlyRunsRequiredChecks() : void
271
271
$ input = new Input ('app ' , ['program ' => $ this ->file ]);
272
272
$ exercise = new CliExerciseImpl ('Some Exercise ' );
273
273
274
- $ checkProphecy1 = $ this ->prophesize (SimpleCheckInterface::class);
275
- $ checkProphecy1 ->canRun ($ exercise ->getType ())->willReturn (true );
276
- $ checkProphecy1 ->getPosition ()->willReturn (SimpleCheckInterface::CHECK_BEFORE );
277
- $ checkProphecy1 ->getExerciseInterface ()->willReturn (ExerciseInterface::class);
278
- $ checkProphecy1 ->check ($ exercise , $ input )->willReturn (new Success ('Success! ' ));
279
-
280
- $ checkProphecy2 = $ this ->prophesize (SimpleCheckInterface::class);
281
- $ checkProphecy2 ->check ($ exercise , $ input )->shouldNotBeCalled ();
282
-
283
- $ check1 = $ checkProphecy1 ->reveal ();
284
- $ check2 = $ checkProphecy2 ->reveal ();
285
-
286
- $ runner = $ this ->prophesize (ExerciseRunnerInterface::class);
287
- $ runner ->getRequiredChecks ()->willReturn ([get_class ($ check1 )]);
288
- $ runner ->verify ($ input )->willReturn (new Success ('Success! ' ));
289
- $ runnerManager = $ this ->prophesize (RunnerManager::class);
290
- $ runnerManager ->getRunner ($ exercise )->willReturn ($ runner ->reveal ());
274
+ $ check1 = $ this
275
+ ->getMockBuilder (SimpleCheckInterface::class)
276
+ ->setMockClassName ('SimpleCheckMock1 ' )
277
+ ->getMock ();
278
+
279
+ $ check1
280
+ ->method ('canRun ' )
281
+ ->willReturn (true );
282
+
283
+ $ check1
284
+ ->method ('getPosition ' )
285
+ ->willReturn (SimpleCheckInterface::CHECK_BEFORE );
286
+
287
+ $ check1
288
+ ->method ('getExerciseInterface ' )
289
+ ->willReturn (ExerciseInterface::class);
290
+
291
+ $ check1
292
+ ->method ('check ' )
293
+ ->with ($ exercise , $ input )
294
+ ->willReturn (new Success ('Success! ' ));
295
+
296
+ $ check2 = $ this
297
+ ->getMockBuilder (SimpleCheckInterface::class)
298
+ ->setMockClassName ('SimpleCheckMock2 ' )
299
+ ->getMock ();
300
+
301
+ $ check2
302
+ ->expects ($ this ->never ())
303
+ ->method ('check ' )
304
+ ->with ($ exercise , $ input );
305
+
306
+ $ runner = $ this ->createMock (ExerciseRunnerInterface::class);
307
+ $ runner
308
+ ->expects ($ this ->once ())
309
+ ->method ('getRequiredChecks ' )
310
+ ->willReturn ([get_class ($ check1 )]);
311
+
312
+ $ runner
313
+ ->method ('verify ' )
314
+ ->with ($ input )
315
+ ->willReturn (new Success ('Success! ' ));
316
+
317
+ $ runnerManager = $ this ->createMock (RunnerManager::class);
318
+ $ runnerManager
319
+ ->method ('getRunner ' )
320
+ ->with ($ exercise )
321
+ ->willReturn ($ runner );
291
322
292
323
$ exerciseDispatcher = new ExerciseDispatcher (
293
- $ runnerManager-> reveal () ,
324
+ $ runnerManager ,
294
325
new ResultAggregator ,
295
- $ this -> prophesize ( EventDispatcher::class)-> reveal ( ),
326
+ new EventDispatcher ( new ResultAggregator () ),
296
327
new CheckRepository ([$ check1 , $ check2 ])
297
328
);
298
329
@@ -346,31 +377,71 @@ public function testWhenBeforeChecksFailTheyReturnImmediately() : void
346
377
$ input = new Input ('app ' , ['program ' => $ this ->file ]);
347
378
$ exercise = new CliExerciseImpl ('Some Exercise ' );
348
379
349
- $ checkProphecy1 = $ this ->prophesize (SimpleCheckInterface::class);
350
- $ checkProphecy1 ->canRun ($ exercise ->getType ())->willReturn (true );
351
- $ checkProphecy1 ->getPosition ()->willReturn (SimpleCheckInterface::CHECK_BEFORE );
352
- $ checkProphecy1 ->getExerciseInterface ()->willReturn (ExerciseInterface::class);
353
- $ checkProphecy1 ->check ($ exercise , $ input )->willReturn (new Failure ('Failure ' , 'nope ' ));
354
-
355
- $ checkProphecy2 = $ this ->prophesize (SimpleCheckInterface::class);
356
- $ checkProphecy2 ->canRun ($ exercise ->getType ())->willReturn (true );
357
- $ checkProphecy2 ->getPosition ()->willReturn (SimpleCheckInterface::CHECK_BEFORE );
358
- $ checkProphecy2 ->getExerciseInterface ()->willReturn (ExerciseInterface::class);
359
- $ checkProphecy2 ->check ($ exercise , $ input )->shouldNotBeCalled ();
360
-
361
- $ check1 = $ checkProphecy1 ->reveal ();
362
- $ check2 = $ checkProphecy2 ->reveal ();
363
-
364
- $ runner = $ this ->prophesize (ExerciseRunnerInterface::class);
365
- $ runner ->getRequiredChecks ()->willReturn ([get_class ($ check1 ), get_class ($ check2 )]);
366
- $ runner ->verify ($ input )->shouldNotBeCalled ();
367
- $ runnerManager = $ this ->prophesize (RunnerManager::class);
368
- $ runnerManager ->getRunner ($ exercise )->willReturn ($ runner ->reveal ());
380
+ $ check1 = $ this
381
+ ->getMockBuilder (SimpleCheckInterface::class)
382
+ ->setMockClassName ('SimpleCheckMock1 ' )
383
+ ->getMock ();
384
+
385
+ $ check1
386
+ ->method ('canRun ' )
387
+ ->willReturn (true );
388
+
389
+ $ check1
390
+ ->method ('getPosition ' )
391
+ ->willReturn (SimpleCheckInterface::CHECK_BEFORE );
392
+
393
+ $ check1
394
+ ->method ('getExerciseInterface ' )
395
+ ->willReturn (ExerciseInterface::class);
396
+
397
+ $ check1
398
+ ->method ('check ' )
399
+ ->with ($ exercise , $ input )
400
+ ->willReturn (new Failure ('Failure ' , 'nope ' ));
401
+
402
+ $ check2 = $ this
403
+ ->getMockBuilder (SimpleCheckInterface::class)
404
+ ->setMockClassName ('SimpleCheckMock2 ' )
405
+ ->getMock ();
406
+
407
+ $ check2
408
+ ->method ('canRun ' )
409
+ ->willReturn (true );
410
+
411
+ $ check2
412
+ ->method ('getPosition ' )
413
+ ->willReturn (SimpleCheckInterface::CHECK_BEFORE );
414
+
415
+ $ check2
416
+ ->method ('getExerciseInterface ' )
417
+ ->willReturn (ExerciseInterface::class);
418
+
419
+ $ check2
420
+ ->expects ($ this ->never ())
421
+ ->method ('check ' )
422
+ ->with ($ exercise , $ input );
423
+
424
+ $ runner = $ this ->createMock (ExerciseRunnerInterface::class);
425
+ $ runner
426
+ ->expects ($ this ->once ())
427
+ ->method ('getRequiredChecks ' )
428
+ ->willReturn ([get_class ($ check1 ), get_class ($ check2 )]);
429
+
430
+ $ runner
431
+ ->expects ($ this ->never ())
432
+ ->method ('verify ' )
433
+ ->with ($ input );
434
+
435
+ $ runnerManager = $ this ->createMock (RunnerManager::class);
436
+ $ runnerManager
437
+ ->method ('getRunner ' )
438
+ ->with ($ exercise )
439
+ ->willReturn ($ runner );
369
440
370
441
$ exerciseDispatcher = new ExerciseDispatcher (
371
- $ runnerManager-> reveal () ,
442
+ $ runnerManager ,
372
443
new ResultAggregator ,
373
- $ this -> prophesize ( EventDispatcher::class)-> reveal ( ),
444
+ new EventDispatcher ( new ResultAggregator () ),
374
445
new CheckRepository ([$ check1 , $ check2 ])
375
446
);
376
447
0 commit comments