Skip to content

Commit a9183cf

Browse files
committed
Merge pull request #116 from php-school/consistent-event-names
BC BREAK: Make event names consisten and coherent
2 parents f75e28f + bd1437f commit a9183cf

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

src/Check/DatabaseCheck.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ public function attach(EventDispatcher $eventDispatcher)
110110
$e->getParameter('exercise')->seed($db);
111111
});
112112

113-
$eventDispatcher->listen('cli.verify.solution-execute.pre', function (CliExecuteEvent $e) {
113+
$eventDispatcher->listen('cli.verify.reference-execute.pre', function (CliExecuteEvent $e) {
114114
$e->prependArg($this->solutionDsn);
115115
});
116116

117117
$eventDispatcher->listen(
118-
['cli.verify.user-execute.pre', 'cli.run.user-execute.pre'],
118+
['cli.verify.student-execute.pre', 'cli.run.student-execute.pre'],
119119
function (CliExecuteEvent $e) {
120120
$e->prependArg($this->userDsn);
121121
}
@@ -133,7 +133,7 @@ function (CliExecuteEvent $e) {
133133

134134
$eventDispatcher->listen(
135135
[
136-
'cli.verify.solution-execute.fail',
136+
'cli.verify.reference-execute.fail',
137137
'verify.finish',
138138
'run.finish'
139139
],

src/ExerciseRunner/CgiRunner.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,24 @@ public function getName()
8585
private function checkRequest(RequestInterface $request, $fileName)
8686
{
8787
try {
88-
$event = $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.verify.solution-execute.pre', $request));
88+
$event = $this->eventDispatcher->dispatch(
89+
new CgiExecuteEvent('cgi.verify.reference-execute.pre', $request)
90+
);
8991
$solutionResponse = $this->executePhpFile(
9092
$this->exercise->getSolution()->getEntryPoint(),
9193
$event->getRequest(),
92-
'solution'
94+
'reference'
9395
);
9496
} catch (CodeExecutionException $e) {
95-
$this->eventDispatcher->dispatch(new Event('cgi.verify.solution-execute.fail', ['exception' => $e]));
97+
$this->eventDispatcher->dispatch(new Event('cgi.verify.reference-execute.fail', ['exception' => $e]));
9698
throw new SolutionExecutionException($e->getMessage());
9799
}
98100

99101
try {
100-
$event = $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.verify.user-execute.pre', $request));
101-
$userResponse = $this->executePhpFile($fileName, $event->getRequest(), 'user');
102+
$event = $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.verify.student-execute.pre', $request));
103+
$userResponse = $this->executePhpFile($fileName, $event->getRequest(), 'student');
102104
} catch (CodeExecutionException $e) {
103-
$this->eventDispatcher->dispatch(new Event('cgi.verify.user-execute.fail', ['exception' => $e]));
105+
$this->eventDispatcher->dispatch(new Event('cgi.verify.student-execute.fail', ['exception' => $e]));
104106
return Failure::fromNameAndCodeExecutionFailure($this->getName(), $e);
105107
}
106108

@@ -215,8 +217,10 @@ public function run($fileName, OutputInterface $output)
215217
{
216218
$success = true;
217219
foreach ($this->exercise->getRequests() as $i => $request) {
218-
$event = $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.run.user-execute.pre', $request));
219-
$process = $this->getProcess($fileName, $event->getRequest());
220+
$event = $this->eventDispatcher->dispatch(
221+
new CgiExecuteEvent('cgi.run.student-execute.pre', $request)
222+
);
223+
$process = $this->getProcess($fileName, $event->getRequest());
220224

221225
$output->writeTitle("Request");
222226
$output->emptyLine();
@@ -225,7 +229,9 @@ public function run($fileName, OutputInterface $output)
225229
$output->writeTitle("Output");
226230
$output->emptyLine();
227231
$process->start();
228-
$this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.run.executing', $request, ['output' => $output]));
232+
$this->eventDispatcher->dispatch(
233+
new CgiExecuteEvent('cgi.run.student.executing', $request, ['output' => $output])
234+
);
229235
$process->wait(function ($outputType, $outputBuffer) use ($output) {
230236
$output->write($outputBuffer);
231237
});

src/ExerciseRunner/CliRunner.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,22 @@ public function verify($fileName)
9797
$args = new ArrayObject($this->exercise->getArgs());
9898

9999
try {
100-
$event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.verify.solution-execute.pre', $args));
100+
$event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.verify.reference-execute.pre', $args));
101101
$solutionOutput = $this->executePhpFile(
102102
$this->exercise->getSolution()->getEntryPoint(),
103103
$event->getArgs(),
104-
'solution'
104+
'reference'
105105
);
106106
} catch (CodeExecutionException $e) {
107-
$this->eventDispatcher->dispatch(new Event('cli.verify.solution-execute.fail', ['exception' => $e]));
107+
$this->eventDispatcher->dispatch(new Event('cli.verify.reference-execute.fail', ['exception' => $e]));
108108
throw new SolutionExecutionException($e->getMessage());
109109
}
110110

111111
try {
112-
$event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.verify.user-execute.pre', $args));
113-
$userOutput = $this->executePhpFile($fileName, $event->getArgs(), 'user');
112+
$event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.verify.student-execute.pre', $args));
113+
$userOutput = $this->executePhpFile($fileName, $event->getArgs(), 'student');
114114
} catch (CodeExecutionException $e) {
115-
$this->eventDispatcher->dispatch(new Event('cli.verify.user-execute.fail', ['exception' => $e]));
115+
$this->eventDispatcher->dispatch(new Event('cli.verify.student-execute.fail', ['exception' => $e]));
116116
return Failure::fromNameAndCodeExecutionFailure($this->getName(), $e);
117117
}
118118
if ($solutionOutput === $userOutput) {
@@ -131,7 +131,7 @@ public function run($fileName, OutputInterface $output)
131131
{
132132
/** @var CliExecuteEvent $event */
133133
$event = $this->eventDispatcher->dispatch(
134-
new CliExecuteEvent('cli.run.user-execute.pre', new ArrayObject($this->exercise->getArgs()))
134+
new CliExecuteEvent('cli.run.student-execute.pre', new ArrayObject($this->exercise->getArgs()))
135135
);
136136

137137
$args = $event->getArgs();
@@ -147,7 +147,9 @@ public function run($fileName, OutputInterface $output)
147147
$output->writeTitle("Output");
148148
$process = $this->getPhpProcess($fileName, $args);
149149
$process->start();
150-
$this->eventDispatcher->dispatch(new CliExecuteEvent('cli.run.executing', $args, ['output' => $output]));
150+
$this->eventDispatcher->dispatch(
151+
new CliExecuteEvent('cli.run.student.executing', $args, ['output' => $output])
152+
);
151153
$process->wait(function ($outputType, $outputBuffer) use ($output) {
152154
$output->writeLine($outputBuffer);
153155
});

0 commit comments

Comments
 (0)