Skip to content

Commit e04dd7f

Browse files
committed
Fixup patching events in case of exceptions
1 parent 60e154c commit e04dd7f

File tree

6 files changed

+9
-115
lines changed

6 files changed

+9
-115
lines changed

app/config.php

+4-19
Original file line numberDiff line numberDiff line change
@@ -387,31 +387,16 @@ function (CgiResult $result) use ($c) {
387387
'application.tear-down' => [
388388
containerListener(CodePatchListener::class, 'revert'),
389389
],
390-
'verify.post.exception' => [
391-
containerListener(CodePatchListener::class, 'revert'),
392-
],
393-
'cli.verify.start' => [
394-
containerListener(CodePatchListener::class, 'patch'),
395-
],
396-
'cli.verify.finish' => [
397-
containerListener(CodePatchListener::class, 'revert'),
398-
],
399-
'cli.run.start' => [
390+
'verify.pre.execute' => [
400391
containerListener(CodePatchListener::class, 'patch'),
401392
],
402-
'cli.run.finish' => [
393+
'verify.post.execute' => [
403394
containerListener(CodePatchListener::class, 'revert'),
404395
],
405-
'cgi.verify.start' => [
406-
containerListener(CodePatchListener::class, 'patch'),
407-
],
408-
'cgi.verify.finish' => [
409-
containerListener(CodePatchListener::class, 'revert'),
410-
],
411-
'cgi.run.start' => [
396+
'run.start' => [
412397
containerListener(CodePatchListener::class, 'patch'),
413398
],
414-
'cgi.run.finish' => [
399+
'run.finish' => [
415400
containerListener(CodePatchListener::class, 'revert'),
416401
],
417402
],

src/Application.php

+3-21
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ public function __construct(string $workshopTitle, string $diConfigFile)
8686

8787
$this->workshopTitle = $workshopTitle;
8888
$this->diConfigFile = $diConfigFile;
89-
90-
set_error_handler([$this, 'handleInternalError']);
9189
}
9290

9391
/**
@@ -196,17 +194,13 @@ public function configure(): ContainerInterface
196194
}
197195
}
198196

199-
$tearDown = function () use ($container): bool {
200-
// TODO: This works.. but wrong event as PatchListener take ExerciseRunnerEvent
197+
set_error_handler(function () use ($container): bool {
201198
$container
202199
->get(EventDispatcher::class)
203200
->dispatch(new Event('application.tear-down'));
204201

205-
// Fallback to default error handler
206-
return false;
207-
};
208-
209-
set_error_handler($tearDown);
202+
return false; // Use default error handler
203+
});
210204

211205
return $container;
212206
}
@@ -288,16 +282,4 @@ private function getContainer(): Container
288282

289283
return $containerBuilder->build();
290284
}
291-
292-
private function handleInternalError(
293-
int $errno,
294-
string $errstr,
295-
string $errfile,
296-
int $errline
297-
): bool {
298-
299-
300-
301-
return false;
302-
}
303285
}

src/ExerciseDispatcher.php

-3
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ public function verify(ExerciseInterface $exercise, Input $input): ResultAggrega
151151

152152
try {
153153
$this->results->add($runner->verify($input));
154-
} catch (\Throwable $e) {
155-
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.post.exception', $exercise, $input));
156-
throw $e;
157154
} finally {
158155
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.post.execute', $exercise, $input));
159156
}

src/Listener/CodePatchListener.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ public function patch(ExerciseRunnerEvent $event): void
4747
$files[] = $exercise->getSolution()->getEntryPoint();
4848
}
4949

50-
foreach ($files as $fileName) {
51-
if (null === $fileName) {
52-
return;
53-
}
54-
50+
foreach (array_filter($files) as $fileName) {
5551
$this->originalCode[$fileName] = (string) file_get_contents($fileName);
5652

5753
file_put_contents(

src/Listener/InMemorySolutionListener.php

-66
This file was deleted.

src/Solution/InMemorySolution.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function fromSolution(SolutionInterface $solution)
6666
}
6767

6868
/**
69-
* Get the entry point. This is the PHP file that PHO would execute in order to run the
69+
* Get the entry point. This is the PHP file that PHP would execute in order to run the
7070
* program. This should be the absolute path.
7171
*
7272
* @return string

0 commit comments

Comments
 (0)