Skip to content

Commit

Permalink
Merge pull request #170 from kagg-design/php-8.4
Browse files Browse the repository at this point in the history
Fix PHP 8.4 deprecation.
  • Loading branch information
antecedent authored Dec 10, 2024
2 parents 57de00f + 920cc75 commit b6d29d6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
composer.lock
tests/cache
vendor/
composer.phar
.DS_Store
Expand Down
7 changes: 6 additions & 1 deletion src/CodeManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ function getCachedPath($file)
if (State::$cacheIndexFile === null) {
$indexPath = Config\getCachePath() . '/index.csv';
if (file_exists($indexPath)) {
$table = array_map('str_getcsv', file($indexPath));
$table = array_map(
static function($line) {
return str_getcsv($line, ',', '"', '\\');
},
file($indexPath)
);
foreach ($table as $row) {
list($key, $value) = $row;
State::$cacheIndex[$key] = $value;
Expand Down
48 changes: 48 additions & 0 deletions tests/get-cached-path.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
Test getCachedPath function (https://github.com/antecedent/patchwork/pull/170)

--FILE--
<?php

require __DIR__ . "/../Patchwork.php";

use Patchwork\CodeManipulation\Stream;

$cachePath = str_replace('\\', '/', __DIR__ . '/cache');
Patchwork\CodeManipulation\State::$cacheIndexFile = null;
Patchwork\Config\State::$cachePath = $cachePath;

if ( ! is_dir($cachePath)) {
mkdir($cachePath);
} else {
echo "The cache directory should not exist in advance.\n";
}

// The expected path depends on the current implementation of getCachedPath().
$file = 'test-file.php';
$hash = md5($file);

$expectedPath = $cachePath . '/' . $hash . '.php';

// First pass - index.csv file does not exist.
$actualPath = \Patchwork\CodeManipulation\getCachedPath($file);

echo $actualPath === $expectedPath ? 'PASS' : 'FAIL';
echo "\n";

// Second pass - index.csv file exists.
$actualPath = \Patchwork\CodeManipulation\getCachedPath($file);

echo $actualPath === $expectedPath ? 'PASS' : 'FAIL';
?>

--CLEAN--
<?php

unlink(__DIR__ . '/cache/index.csv');
rmdir(__DIR__ . '/cache');

?>
--EXPECT--
PASS
PASS

0 comments on commit b6d29d6

Please sign in to comment.