From 61bb92ff7df28c9c1e69734134b8bc2ec4a0d318 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 23:38:22 +0200 Subject: [PATCH 1/8] Fix PHP 8.4 deprecation. --- src/CodeManipulation.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CodeManipulation.php b/src/CodeManipulation.php index 6f07094..aa9bb4a 100644 --- a/src/CodeManipulation.php +++ b/src/CodeManipulation.php @@ -63,7 +63,13 @@ 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) { + /** @noinspection PhpRedundantOptionalArgumentInspection */ + return str_getcsv($line, ',', '"', '\\'); + }, + file($indexPath) + ); foreach ($table as $row) { list($key, $value) = $row; State::$cacheIndex[$key] = $value; From 0d2e52fb81fb99775be225cb98e30897e4e8f19c Mon Sep 17 00:00:00 2001 From: kagg-design Date: Mon, 2 Dec 2024 12:07:27 +0200 Subject: [PATCH 2/8] Remove @noinspection comment. --- src/CodeManipulation.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CodeManipulation.php b/src/CodeManipulation.php index aa9bb4a..1f13a19 100644 --- a/src/CodeManipulation.php +++ b/src/CodeManipulation.php @@ -65,7 +65,6 @@ function getCachedPath($file) if (file_exists($indexPath)) { $table = array_map( static function($line) { - /** @noinspection PhpRedundantOptionalArgumentInspection */ return str_getcsv($line, ',', '"', '\\'); }, file($indexPath) From 12db4fd6c0f1bd96b6973fac28a55b63032f2f82 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 7 Dec 2024 19:25:20 +0200 Subject: [PATCH 3/8] Add .phpt test. --- tests/get-cached-path.phpt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/get-cached-path.phpt diff --git a/tests/get-cached-path.phpt b/tests/get-cached-path.phpt new file mode 100644 index 0000000..eba8b80 --- /dev/null +++ b/tests/get-cached-path.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test getCachedPath function + +--FILE-- + + +--EXPECT-- +PASS +PASS From 4b64bbf389e8aa13dd8ee464662c1407ef969c7e Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 7 Dec 2024 19:35:19 +0200 Subject: [PATCH 4/8] Create cache dir. --- .gitignore | 1 + tests/get-cached-path.phpt | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 28bd844..5c319eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ composer.lock +tests/cache vendor/ composer.phar .DS_Store diff --git a/tests/get-cached-path.phpt b/tests/get-cached-path.phpt index eba8b80..9bbb49b 100644 --- a/tests/get-cached-path.phpt +++ b/tests/get-cached-path.phpt @@ -12,6 +12,10 @@ $cachePath = str_replace('\\', '/', __DIR__ . '/cache'); Patchwork\CodeManipulation\State::$cacheIndexFile = null; Patchwork\Config\State::$cachePath = $cachePath; +if ( ! is_dir($cachePath)) { + mkdir($cachePath); +} + // Test getCachedPath function $file = 'test-file.php'; $hash = md5($file); From 0781ff07f0148907b9d732d9cbf2f869d173cd55 Mon Sep 17 00:00:00 2001 From: Ignas Rudaitis Date: Mon, 9 Dec 2024 11:16:06 +0200 Subject: [PATCH 5/8] Make propotest follow prior conventions --- tests/get-cached-path.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/get-cached-path.phpt b/tests/get-cached-path.phpt index 9bbb49b..9493508 100644 --- a/tests/get-cached-path.phpt +++ b/tests/get-cached-path.phpt @@ -1,5 +1,5 @@ --TEST-- -Test getCachedPath function +Test getCachedPath function (https://github.com/antecedent/patchwork/pull/170) --FILE-- Date: Tue, 10 Dec 2024 09:53:19 +0200 Subject: [PATCH 6/8] Ensure filesystem idempotency in test case --- tests/get-cached-path.phpt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/get-cached-path.phpt b/tests/get-cached-path.phpt index 9493508..ab08cf6 100644 --- a/tests/get-cached-path.phpt +++ b/tests/get-cached-path.phpt @@ -14,6 +14,8 @@ 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(). @@ -34,6 +36,13 @@ $actualPath = \Patchwork\CodeManipulation\getCachedPath($file); echo $actualPath === $expectedPath ? 'PASS' : 'FAIL'; ?> +--CLEAN-- + --EXPECT-- PASS PASS From 27ae2b632aa9891bd4044baec773e4680e5d0d89 Mon Sep 17 00:00:00 2001 From: Ignas Rudaitis Date: Tue, 10 Dec 2024 09:56:22 +0200 Subject: [PATCH 7/8] Reindent to follow a local convention --- src/CodeManipulation.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CodeManipulation.php b/src/CodeManipulation.php index 1f13a19..8b740f8 100644 --- a/src/CodeManipulation.php +++ b/src/CodeManipulation.php @@ -64,10 +64,10 @@ function getCachedPath($file) $indexPath = Config\getCachePath() . '/index.csv'; if (file_exists($indexPath)) { $table = array_map( - static function($line) { - return str_getcsv($line, ',', '"', '\\'); - }, - file($indexPath) + static function($line) { + return str_getcsv($line, ',', '"', '\\'); + }, + file($indexPath) ); foreach ($table as $row) { list($key, $value) = $row; From 920cc754e9bc7ca2defeffdabe27b9a0a8488d7f Mon Sep 17 00:00:00 2001 From: Ignas Rudaitis Date: Tue, 10 Dec 2024 09:58:20 +0200 Subject: [PATCH 8/8] Reindent to follow a local convention (attempt 2) --- src/CodeManipulation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CodeManipulation.php b/src/CodeManipulation.php index 8b740f8..96d9b3e 100644 --- a/src/CodeManipulation.php +++ b/src/CodeManipulation.php @@ -64,9 +64,9 @@ function getCachedPath($file) $indexPath = Config\getCachePath() . '/index.csv'; if (file_exists($indexPath)) { $table = array_map( - static function($line) { + static function($line) { return str_getcsv($line, ',', '"', '\\'); - }, + }, file($indexPath) ); foreach ($table as $row) {