Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP 8.4 deprecation. #170

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}
antecedent marked this conversation as resolved.
Show resolved Hide resolved

// 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--
antecedent marked this conversation as resolved.
Show resolved Hide resolved
PASS
PASS
Loading