From 359889c0db83e974cb6b29982b08d21f40ebca3f Mon Sep 17 00:00:00 2001 From: ramchale Date: Thu, 14 Nov 2024 12:34:43 +0000 Subject: [PATCH] Add tests additional tests for existing file path Signed-off-by: ramchale --- psalm-baseline.xml | 1 + test/RealPathTest.php | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 2240d10a..d6c7d4e2 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -809,6 +809,7 @@ + diff --git a/test/RealPathTest.php b/test/RealPathTest.php index 6aba8a09..943c7e6e 100644 --- a/test/RealPathTest.php +++ b/test/RealPathTest.php @@ -17,14 +17,35 @@ class RealPathTest extends TestCase { - public function testExistingFileReturnsRealPath(): void + public static function returnExistingFilePathDataProvider(): array + { + return [ + [__DIR__ . '/_files/file.1'], + [__DIR__ . '/_files/../_files/file.1'], + [__DIR__ . '/_files/././file.1'], + [__DIR__ . '///_files///file.1'], + ]; + } + + #[DataProvider('returnExistingFilePathDataProvider')] + public function testExistingFileReturnsRealPath(string $filePath): void + { + $filter = new RealPathFilter(); + + $result = $filter->filter($filePath); + + self::assertSame(__DIR__ . '/_files/file.1', $result); + } + + public function testPathWithNonExistingPartsButRealResolutionIsNotValid(): void { $filter = new RealPathFilter(); - $filename = __DIR__ . '/_files/file.1'; - $result = $filter->filter($filename); + $path = __DIR__ . '/_files/foo/../bar/../file.1'; + + $result = $filter->filter($path); - self::assertStringContainsString($filename, $result); + self::assertSame($path, $result); } public function testNonexistentFileReturnsValuePassedToFilter(): void