Skip to content

Commit

Permalink
Add tests additional tests for existing file path
Browse files Browse the repository at this point in the history
Signed-off-by: ramchale <[email protected]>
  • Loading branch information
ramchale committed Nov 14, 2024
1 parent 2337e18 commit 359889c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@
</file>
<file src="test/RealPathTest.php">
<PossiblyUnusedMethod>
<code><![CDATA[returnExistingFilePathDataProvider]]></code>
<code><![CDATA[returnNonExistentPathDataProvider]]></code>
<code><![CDATA[returnUnfilteredDataProvider]]></code>
</PossiblyUnusedMethod>
Expand Down
29 changes: 25 additions & 4 deletions test/RealPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 359889c

Please sign in to comment.