14
14
use PhpSchool \PhpWorkshop \ExerciseCheck \DatabaseExerciseCheck ;
15
15
use PhpSchool \PhpWorkshop \ExerciseDispatcher ;
16
16
use PhpSchool \PhpWorkshop \ExerciseRunner \CliRunner ;
17
- use PhpSchool \PhpWorkshop \Factory \ RunnerFactory ;
17
+ use PhpSchool \PhpWorkshop \ExerciseRunner \ RunnerManager ;
18
18
use PhpSchool \PhpWorkshop \Input \Input ;
19
19
use PhpSchool \PhpWorkshop \Output \OutputInterface ;
20
20
use PhpSchool \PhpWorkshop \ResultAggregator ;
@@ -61,6 +61,7 @@ public function setUp()
61
61
62
62
$ this ->check = new DatabaseCheck ;
63
63
$ this ->exercise = $ this ->createMock (DatabaseExerciseInterface::class);
64
+ $ this ->exercise ->expects ($ this ->any ())->method ('getType ' )->willReturn (ExerciseType::CLI ());
64
65
$ this ->dbDir = sprintf (
65
66
'%s/PhpSchool_PhpWorkshop_Check_DatabaseCheck ' ,
66
67
str_replace ('\\' , '/ ' , realpath (sys_get_temp_dir ()))
@@ -75,20 +76,25 @@ public function setUp()
75
76
* @param EventDispatcher $eventDispatcher
76
77
* @return \PHPUnit_Framework_MockObject_MockObject
77
78
*/
78
- private function getRunnerFactory (ExerciseInterface $ exercise , EventDispatcher $ eventDispatcher )
79
+ private function getRunnerManager (ExerciseInterface $ exercise , EventDispatcher $ eventDispatcher )
79
80
{
80
81
$ runner = $ this ->getMockBuilder (CliRunner::class)
81
82
->setConstructorArgs ([$ exercise , $ eventDispatcher ])
82
- ->setMethods (['configure ' ])
83
+ ->setMethods (['configure ' , ' getRequiredChecks ' ])
83
84
->getMock ();
84
85
85
- $ runnerFactory = $ this ->createMock (RunnerFactory::class);
86
- $ runnerFactory
86
+ $ runner
87
+ ->expects ($ this ->any ())
88
+ ->method ('getRequiredChecks ' )
89
+ ->willReturn ([]);
90
+
91
+ $ runnerManager = $ this ->createMock (RunnerManager::class);
92
+ $ runnerManager
87
93
->expects ($ this ->once ())
88
- ->method ('create ' )
94
+ ->method ('getRunner ' )
89
95
->willReturn ($ runner );
90
96
91
- return $ runnerFactory ;
97
+ return $ runnerManager ;
92
98
}
93
99
94
100
public function testIfDatabaseFolderExistsExceptionIsThrown ()
@@ -153,7 +159,7 @@ public function testIfPDOThrowsExceptionItCleansUp()
153
159
$ results = new ResultAggregator ;
154
160
$ eventDispatcher = new EventDispatcher ($ results );
155
161
$ dispatcher = new ExerciseDispatcher (
156
- $ this ->getRunnerFactory ($ this ->exercise , $ eventDispatcher ),
162
+ $ this ->getRunnerManager ($ this ->exercise , $ eventDispatcher ),
157
163
$ results ,
158
164
$ eventDispatcher ,
159
165
$ this ->checkRepository
@@ -194,7 +200,7 @@ public function testSuccessIsReturnedIfDatabaseVerificationPassed()
194
200
$ results = new ResultAggregator ;
195
201
$ eventDispatcher = new EventDispatcher ($ results );
196
202
$ dispatcher = new ExerciseDispatcher (
197
- $ this ->getRunnerFactory ($ this ->exercise , $ eventDispatcher ),
203
+ $ this ->getRunnerManager ($ this ->exercise , $ eventDispatcher ),
198
204
$ results ,
199
205
$ eventDispatcher ,
200
206
$ this ->checkRepository
@@ -225,7 +231,7 @@ public function testRunExercise()
225
231
$ results = new ResultAggregator ;
226
232
$ eventDispatcher = new EventDispatcher ($ results );
227
233
$ dispatcher = new ExerciseDispatcher (
228
- $ this ->getRunnerFactory ($ this ->exercise , $ eventDispatcher ),
234
+ $ this ->getRunnerManager ($ this ->exercise , $ eventDispatcher ),
229
235
$ results ,
230
236
$ eventDispatcher ,
231
237
$ this ->checkRepository
@@ -241,6 +247,8 @@ public function testRunExercise()
241
247
public function testFailureIsReturnedIfDatabaseVerificationFails ()
242
248
{
243
249
$ solution = SingleFileSolution::fromFile (realpath (__DIR__ . '/../res/database/solution.php ' ));
250
+
251
+
244
252
$ this ->exercise
245
253
->expects ($ this ->once ())
246
254
->method ('getSolution ' )
@@ -269,7 +277,7 @@ public function testFailureIsReturnedIfDatabaseVerificationFails()
269
277
$ results = new ResultAggregator ;
270
278
$ eventDispatcher = new EventDispatcher ($ results );
271
279
$ dispatcher = new ExerciseDispatcher (
272
- $ this ->getRunnerFactory ($ this ->exercise , $ eventDispatcher ),
280
+ $ this ->getRunnerManager ($ this ->exercise , $ eventDispatcher ),
273
281
$ results ,
274
282
$ eventDispatcher ,
275
283
$ this ->checkRepository
@@ -337,7 +345,7 @@ public function testAlteringDatabaseInSolutionDoesNotEffectDatabaseInUserSolutio
337
345
$ results = new ResultAggregator ;
338
346
$ eventDispatcher = new EventDispatcher ($ results );
339
347
$ dispatcher = new ExerciseDispatcher (
340
- $ this ->getRunnerFactory ($ this ->exercise , $ eventDispatcher ),
348
+ $ this ->getRunnerManager ($ this ->exercise , $ eventDispatcher ),
341
349
$ results ,
342
350
$ eventDispatcher ,
343
351
$ this ->checkRepository
0 commit comments