9
9
use PhpSchool \PhpWorkshop \Exercise \ExerciseInterface ;
10
10
use PhpSchool \PhpWorkshop \Exercise \ExerciseType ;
11
11
use PhpSchool \PhpWorkshop \ExerciseCheck \ComposerExerciseCheck ;
12
+ use PhpSchool \PhpWorkshop \ExerciseRunner \Context \ExecutionContext ;
12
13
use PhpSchool \PhpWorkshop \Input \Input ;
13
14
use PhpSchool \PhpWorkshop \Result \ComposerFailure ;
14
15
use PhpSchool \PhpWorkshop \Result \Failure ;
@@ -34,30 +35,29 @@ public function getName(): string
34
35
* installed a set of required packages. If they did not a failure is returned, otherwise,
35
36
* a success is returned.
36
37
*
37
- * @param ExerciseInterface $exercise The exercise to check against.
38
- * @param Input $input The command line arguments passed to the command.
38
+ * @param ExecutionContext $context The current execution context, containing the exercise, input and working directories.
39
39
* @return ResultInterface The result of the check.
40
- * @noinspection SpellCheckingInspection
41
40
*/
42
- public function check (ExerciseInterface $ exercise , Input $ input ): ResultInterface
41
+ public function check (ExecutionContext $ context ): ResultInterface
43
42
{
43
+ $ exercise = $ context ->getExercise ();
44
44
if (!$ exercise instanceof ComposerExerciseCheck) {
45
45
throw new InvalidArgumentException ();
46
46
}
47
47
48
- if (!file_exists (sprintf ('%s/composer.json ' , dirname ( $ input -> getRequiredArgument ( ' program ' ) )))) {
48
+ if (!file_exists (sprintf ('%s/composer.json ' , $ context -> getStudentExecutionDirectory ( )))) {
49
49
return ComposerFailure::fromCheckAndMissingFileOrFolder ($ this , 'composer.json ' );
50
50
}
51
51
52
- if (!file_exists (sprintf ('%s/composer.lock ' , dirname ( $ input -> getRequiredArgument ( ' program ' ) )))) {
52
+ if (!file_exists (sprintf ('%s/composer.lock ' , $ context -> getStudentExecutionDirectory ( )))) {
53
53
return ComposerFailure::fromCheckAndMissingFileOrFolder ($ this , 'composer.lock ' );
54
54
}
55
55
56
- if (!file_exists (sprintf ('%s/vendor ' , dirname ( $ input -> getRequiredArgument ( ' program ' ) )))) {
56
+ if (!file_exists (sprintf ('%s/vendor ' , $ context -> getStudentExecutionDirectory ( )))) {
57
57
return ComposerFailure::fromCheckAndMissingFileOrFolder ($ this , 'vendor ' );
58
58
}
59
59
60
- $ lockFile = new LockFileParser (sprintf ('%s/composer.lock ' , dirname ( $ input -> getRequiredArgument ( ' program ' ) )));
60
+ $ lockFile = new LockFileParser (sprintf ('%s/composer.lock ' , $ context -> getStudentExecutionDirectory ( )));
61
61
$ missingPackages = array_filter ($ exercise ->getRequiredPackages (), function ($ package ) use ($ lockFile ) {
62
62
return !$ lockFile ->hasInstalledPackage ($ package );
63
63
});
0 commit comments