Skip to content

Commit

Permalink
fix issue #176
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Feb 13, 2023
1 parent 3ce8ba3 commit ec9fab6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\TraceableAdapter;

use Symfony\Contracts\Cache\ItemInterface;
use function class_exists;
use function get_debug_type;
use function is_string;
use function md5_file;
use function sprintf;
use function str_contains;
use function str_replace;
use function str_split;

/**
* @author Overtrue
Expand Down Expand Up @@ -138,6 +140,6 @@ public function __debugInfo(): ?array

private function getKey(string $filename): string
{
return str_replace('/', '_', $filename);
return str_replace(str_split(ItemInterface::RESERVED_CHARACTERS), '_', $filename);
}
}
16 changes: 16 additions & 0 deletions tests/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ public function testGetCalls(): void
$this->assertCount(3, self::$cache->getCalls());
}

/**
* @covers \Overtrue\PHPLint\Cache::saveItem
*/
public function testFilenameHasReservedCharacters(): void
{
$filename = dirname(__DIR__) . '/EndToEnd/[email protected]';
$fingerprint = md5_file($filename);

$cacheItem = self::$cache->getItem($filename);
$cacheItem->set($fingerprint);
$saved = self::$cache->saveItem($cacheItem);

$this->assertTrue($saved);
$this->assertEquals($fingerprint, self::$cache->getItem($filename)->get());
}

private function generateItems(array $values): Generator
{
foreach ($values as $filename => $processor) {
Expand Down
2 changes: 1 addition & 1 deletion tests/EndToEnd/LintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testLintDirectoryWithoutConfigurationAndCache(): void

$this->commandTester->assertCommandIsSuccessful();
$this->assertCount(
1,
2,
$this->command->getResults()->getMisses()
);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/EndToEnd/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// @link https://github.com/overtrue/phplint/issues/176
1 change: 1 addition & 0 deletions tests/Finder/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function testSearchPhpFilesWithCondition(): void
'Configuration/ConsoleConfigTest.php',
'Configuration/YamlConfigTest.php',
'EndToEnd/LintCommandTest.php',
'EndToEnd/[email protected]',
'Finder/FinderTest.php',
'TestCase.php',
],
Expand Down

0 comments on commit ec9fab6

Please sign in to comment.