-
Notifications
You must be signed in to change notification settings - Fork 4
Code patch updates #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code patch updates #201
Conversation
- Patches internal solution - Internal solution is patched in temp - Solution is ran from temp - Eliminates chance of internal solution becoming "broken" - Users solution is patched in place - Error handler catches app errors and patches are reverted
'%s/../../exercises/%s/solution/solution.php', | ||
dirname((string) (new ReflectionClass(static::class))->getFileName()), | ||
self::normaliseName($this->getName()) | ||
if (null === $this->solution) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this was required and probs also for dir solution... the problem being that a patched solution in temp was being overwritten due to the solution being copied on construct and we're constructing fresh on each call to getSolution.
Probably a better fix here, maybe moving the copy to temp dir to somewhere that isn't on solution construct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AydinHassan I need your input on this one bro, can you think of a cleaner approach that for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm not really off the top of my head. I think it's fine as you have it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the only problem I foresee here is the implementation of a solution inside the exercise instead of using the Abstract. e.g if you need a dir solution and you use the static factory 🤔
ad0bcb6
to
e04dd7f
Compare
note to self, a current failure that needs a failing test case writing up this happens when an exercise is not selected and a run or verify is attempted
|
41e11de
to
3342864
Compare
src/Application.php
Outdated
@@ -227,6 +237,10 @@ public function run(): int | |||
$message = str_replace($basePath, '', $message); | |||
} | |||
|
|||
$container | |||
->get(EventDispatcher::class) | |||
->dispatch(new Event('application.tear-down')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I was thinking, if an exception ever happened in a listener then it would bubble up and mask the original exception.
It could be the initial exception is something we WANT to show the user, and thus an exception covering this up during some failed cleanup process is not something we want the user to see really.
@AydinHassan thoughts? We could move this dispatch into a separate method that tries and catches and either ignores or logs and lets the application carry on the closing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikeymike I think logging sounds like a good idea
src/Application.php
Outdated
@@ -227,6 +237,10 @@ public function run(): int | |||
$message = str_replace($basePath, '', $message); | |||
} | |||
|
|||
$container | |||
->get(EventDispatcher::class) | |||
->dispatch(new Event('application.tear-down')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikeymike I think logging sounds like a good idea
$intersection = array_intersect($currentPath, $solutionPath); | ||
|
||
if (count($intersection) <= 1) { | ||
$intersection = explode('/', $tempDir); | ||
} | ||
|
||
$basename = implode('/', array_diff($solutionPath, $intersection)); | ||
$entrypoint = implode('/', array_diff($entryPointPath, $intersection)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually have no idea what this chuck is doing - can you extract it to a method and maybe add a comment or just give it a good name?
$tmpDir = realpath(sys_get_temp_dir()); | ||
|
||
if (!$tmpDir) { | ||
throw new \RuntimeException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a message to the exception - also we do have our own RuntimeException
you could use
$realpath = realpath($path); | ||
|
||
if (false === $realpath) { | ||
throw new \RuntimeException(sprintf('Failed to get realpath of "%s"', $path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, let's use our own RuntimeException
@@ -0,0 +1,119 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there are no tests for this
@mikeymike Might be worth splitting up and getting some of this work in? Probably the events stuff can go separately, the patches, and the FS utils ? |
Superseded by multiple PRs |
Patches internal solution
Users solution is patched in place