From fdf1649e5a2b57770822328f58d6d71e543b2129 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Thu, 9 Feb 2023 22:59:56 +0100 Subject: [PATCH] getEntryPoint now returns a SolutionFile instance --- src/ExerciseRunner/CgiRunner.php | 2 +- src/ExerciseRunner/CliRunner.php | 2 +- src/Listener/CodePatchListener.php | 2 +- src/Solution/DirectorySolution.php | 12 +++++++----- src/Solution/SingleFileSolution.php | 8 ++++---- src/Solution/SolutionInterface.php | 6 +++--- test/Listener/CodePatchListenerTest.php | 2 +- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/ExerciseRunner/CgiRunner.php b/src/ExerciseRunner/CgiRunner.php index 3be3ef14..5fbfc710 100644 --- a/src/ExerciseRunner/CgiRunner.php +++ b/src/ExerciseRunner/CgiRunner.php @@ -121,7 +121,7 @@ private function checkRequest(RequestInterface $request, string $fileName): CgiR new CgiExecuteEvent('cgi.verify.reference-execute.pre', $request) ); $solutionResponse = $this->executePhpFile( - $this->exercise->getSolution()->getEntryPoint(), + $this->exercise->getSolution()->getEntryPoint()->getAbsolutePath(), $event->getRequest(), 'reference' ); diff --git a/src/ExerciseRunner/CliRunner.php b/src/ExerciseRunner/CliRunner.php index 0c51f71d..fa204766 100644 --- a/src/ExerciseRunner/CliRunner.php +++ b/src/ExerciseRunner/CliRunner.php @@ -205,7 +205,7 @@ private function doVerify(array $args, Input $input): CliResultInterface /** @var CliExecuteEvent $event */ $event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.verify.reference-execute.pre', $args)); $solutionOutput = $this->executePhpFile( - $this->exercise->getSolution()->getEntryPoint(), + $this->exercise->getSolution()->getEntryPoint()->getAbsolutePath(), $event->getArgs(), 'reference' ); diff --git a/src/Listener/CodePatchListener.php b/src/Listener/CodePatchListener.php index 5cfc63d4..eda7abe2 100644 --- a/src/Listener/CodePatchListener.php +++ b/src/Listener/CodePatchListener.php @@ -57,7 +57,7 @@ public function patch(ExerciseRunnerEvent $event): void $exercise = $event->getExercise(); if ($exercise instanceof ProvidesSolution) { - $files[] = $exercise->getSolution()->getEntryPoint(); + $files[] = $exercise->getSolution()->getEntryPoint()->getAbsolutePath(); } foreach (array_filter($files) as $fileName) { diff --git a/src/Solution/DirectorySolution.php b/src/Solution/DirectorySolution.php index 142472c8..2e8c9d8a 100644 --- a/src/Solution/DirectorySolution.php +++ b/src/Solution/DirectorySolution.php @@ -16,7 +16,7 @@ class DirectorySolution implements SolutionInterface { /** - * @var string + * @var SolutionFile */ private $entryPoint; @@ -72,7 +72,9 @@ public function __construct(string $directory, string $entryPoint, array $exclus return new SolutionFile($file, $directory); }, $files); - $this->entryPoint = sprintf('%s/%s', $directory, $entryPoint); + $this->entryPoint = array_values(array_filter($this->files, function (SolutionFile $file) use ($entryPoint) { + return $file->getRelativePath() === $entryPoint; + }))[0]; $this->baseDirectory = $directory; } @@ -92,11 +94,11 @@ public static function fromDirectory(string $directory, array $exclusions = [], /** * Get the entry point. This is the PHP file that PHO would execute in order to run the - * program. This should be the absolute path. + * program. * - * @return string + * @return SolutionFile */ - public function getEntryPoint(): string + public function getEntryPoint(): SolutionFile { return $this->entryPoint; } diff --git a/src/Solution/SingleFileSolution.php b/src/Solution/SingleFileSolution.php index 4a0fbfb5..3964c91d 100644 --- a/src/Solution/SingleFileSolution.php +++ b/src/Solution/SingleFileSolution.php @@ -43,13 +43,13 @@ public static function fromFile(string $file): self /** * Get the entry point. This is the PHP file that php would execute in order to run the - * program. This should be the absolute path. + * program. * - * @return string + * @return SolutionFile */ - public function getEntryPoint(): string + public function getEntryPoint(): SolutionFile { - return $this->file->__toString(); + return $this->file; } /** diff --git a/src/Solution/SolutionInterface.php b/src/Solution/SolutionInterface.php index 890eb34c..db2cabfe 100644 --- a/src/Solution/SolutionInterface.php +++ b/src/Solution/SolutionInterface.php @@ -11,11 +11,11 @@ interface SolutionInterface { /** * Get the entry point. This is the PHP file that php would execute in order to run the - * program. This should be the absolute path. + * program. * - * @return string + * @return SolutionFile */ - public function getEntryPoint(): string; + public function getEntryPoint(): SolutionFile; /** * Get all the files which are contained with the solution. diff --git a/test/Listener/CodePatchListenerTest.php b/test/Listener/CodePatchListenerTest.php index 227b76a0..503ef535 100644 --- a/test/Listener/CodePatchListenerTest.php +++ b/test/Listener/CodePatchListenerTest.php @@ -113,7 +113,7 @@ public function testPatchesProvidedSolution(): void $listener->patch($event); self::assertStringEqualsFile($this->file, 'MODIFIED CONTENT'); - self::assertStringEqualsFile($exercise->getSolution()->getEntryPoint(), 'MODIFIED CONTENT'); + self::assertStringEqualsFile($exercise->getSolution()->getEntryPoint()->getAbsolutePath(), 'MODIFIED CONTENT'); } public function testFileIsLoggedWhenPatches(): void