Skip to content

Commit a395588

Browse files
authored
Merge pull request #137 from php-school/runners-configure-commands
Runners configure commands
2 parents 270f19e + 934892a commit a395588

36 files changed

+1822
-1298
lines changed

app/config.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
use PhpSchool\PhpWorkshop\CodePatcher;
2121
use PhpSchool\PhpWorkshop\Event\EventDispatcher;
2222
use PhpSchool\PhpWorkshop\ExerciseDispatcher;
23+
use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CgiRunnerFactory;
24+
use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CliRunnerFactory;
25+
use PhpSchool\PhpWorkshop\ExerciseRunner\RunnerManager;
2326
use PhpSchool\PhpWorkshop\Factory\EventDispatcherFactory;
2427
use PhpSchool\PhpWorkshop\Factory\MenuFactory;
2528
use PhpSchool\PhpWorkshop\Factory\ResultRendererFactory;
26-
use PhpSchool\PhpWorkshop\Factory\RunnerFactory;
2729
use PhpSchool\PhpWorkshop\Listener\CheckExerciseAssignedListener;
2830
use PhpSchool\PhpWorkshop\Listener\CodePatchListener;
31+
use PhpSchool\PhpWorkshop\Listener\ConfigureCommandListener;
2932
use PhpSchool\PhpWorkshop\Listener\PrepareSolutionListener;
3033
use PhpSchool\PhpWorkshop\Listener\SelfCheckListener;
3134
use PhpSchool\PhpWorkshop\MenuItem\ResetProgress;
@@ -63,7 +66,7 @@
6366
WorkshopType::class => WorkshopType::STANDARD(),
6467
ExerciseDispatcher::class => function (ContainerInterface $c) {
6568
return new ExerciseDispatcher(
66-
$c->get(RunnerFactory::class),
69+
$c->get(RunnerManager::class),
6770
$c->get(ResultAggregator::class),
6871
$c->get(EventDispatcher::class),
6972
$c->get(CheckRepository::class)
@@ -86,8 +89,8 @@
8689
new CommandDefinition('menu', [], MenuCommand::class),
8790
new CommandDefinition('help', [], HelpCommand::class),
8891
new CommandDefinition('print', [], PrintCommand::class),
89-
new CommandDefinition('verify', ['program'], VerifyCommand::class),
90-
new CommandDefinition('run', ['program'], RunCommand::class),
92+
new CommandDefinition('verify', [], VerifyCommand::class),
93+
new CommandDefinition('run', [], RunCommand::class),
9194
new CommandDefinition('credits', [], CreditsCommand::class)
9295
],
9396
'menu',
@@ -117,7 +120,12 @@
117120
EventDispatcherFactory::class => object(),
118121

119122
//Exercise Runners
120-
RunnerFactory::class => object(),
123+
RunnerManager::class => function (ContainerInterface $c) {
124+
$manager = new RunnerManager;
125+
$manager->addFactory(new CliRunnerFactory($c->get(EventDispatcher::class)));
126+
$manager->addFactory(new CgiRunnerFactory($c->get(EventDispatcher::class)));
127+
return $manager;
128+
},
121129

122130
//commands
123131
MenuCommand::class => function (ContainerInterface $c) {
@@ -172,16 +180,23 @@
172180
},
173181

174182
//Listeners
175-
PrepareSolutionListener::class => object(),
176-
CodePatchListener::class => function (ContainerInterface $c) {
183+
PrepareSolutionListener::class => object(),
184+
CodePatchListener::class => function (ContainerInterface $c) {
177185
return new CodePatchListener($c->get(CodePatcher::class));
178186
},
179-
SelfCheckListener::class => function (ContainerInterface $c) {
187+
SelfCheckListener::class => function (ContainerInterface $c) {
180188
return new SelfCheckListener($c->get(ResultAggregator::class));
181189
},
182190
CheckExerciseAssignedListener::class => function (ContainerInterface $c) {
183191
return new CheckExerciseAssignedListener($c->get(UserState::class));
184192
},
193+
ConfigureCommandListener::class => function (ContainerInterface $c) {
194+
return new ConfigureCommandListener(
195+
$c->get(UserState::class),
196+
$c->get(ExerciseRepository::class),
197+
$c->get(RunnerManager::class)
198+
);
199+
},
185200

186201
//checks
187202
FileExistsCheck::class => object(),
@@ -271,6 +286,11 @@
271286
containerListener(CheckExerciseAssignedListener::class)
272287
],
273288
],
289+
'configure-command-arguments' => [
290+
'route.pre.resolve.args' => [
291+
containerListener(ConfigureCommandListener::class)
292+
],
293+
],
274294
'prepare-solution' => [
275295
'verify.start' => [
276296
containerListener(PrepareSolutionListener::class),

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
"nikic/php-parser": "^2.1"
3434
},
3535
"require-dev": {
36-
"composer/composer": "^1.0-alpha",
37-
"phpunit/phpunit": "^5.4",
36+
"composer/composer": "^1.2",
37+
"phpunit/phpunit": "^5.6",
38+
"phpunit/phpunit-mock-objects": "^3.3",
3839
"squizlabs/php_codesniffer": "^2.4"
3940
},
4041
"autoload" : {

0 commit comments

Comments
 (0)