From c9180e590ed220650d103c7dddb319701ec19d26 Mon Sep 17 00:00:00 2001 From: Mohammad Zahed Date: Wed, 7 Jun 2023 14:56:19 +0300 Subject: [PATCH 1/5] Update directory targeting logic to support glob patterns --- src/PendingCalls/UsesCall.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/PendingCalls/UsesCall.php b/src/PendingCalls/UsesCall.php index fc297698..8dfd9289 100644 --- a/src/PendingCalls/UsesCall.php +++ b/src/PendingCalls/UsesCall.php @@ -84,8 +84,10 @@ final class UsesCall }, $targets); $this->targets = array_reduce($targets, function (array $accumulator, string $target): array { - if (is_dir($target) || file_exists($target)) { - $accumulator[] = (string) realpath($target); + if ($matches = glob($target)) { + foreach ($matches as $file) { + $accumulator[] = (string) realpath($file); + } } return $accumulator; From e00efb1b6d18d0628a43ecd425fef50906f7e19d Mon Sep 17 00:00:00 2001 From: Mohammad Zahed Date: Thu, 8 Jun 2023 14:50:25 +0300 Subject: [PATCH 2/5] add tests for directory and file patterns --- tests/PHPUnit/CustomTestCase/UsesPerDirectoryAsPattern.php | 7 +++++++ tests/PHPUnit/CustomTestCase/UsesPerFileAsPattern.php | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/PHPUnit/CustomTestCase/UsesPerDirectoryAsPattern.php create mode 100644 tests/PHPUnit/CustomTestCase/UsesPerFileAsPattern.php diff --git a/tests/PHPUnit/CustomTestCase/UsesPerDirectoryAsPattern.php b/tests/PHPUnit/CustomTestCase/UsesPerDirectoryAsPattern.php new file mode 100644 index 00000000..5e8546f4 --- /dev/null +++ b/tests/PHPUnit/CustomTestCase/UsesPerDirectoryAsPattern.php @@ -0,0 +1,7 @@ +in('../*/'); + +test('closure was bound to CustomTestCase', function () { + $this->assertCustomTrue(); +}); diff --git a/tests/PHPUnit/CustomTestCase/UsesPerFileAsPattern.php b/tests/PHPUnit/CustomTestCase/UsesPerFileAsPattern.php new file mode 100644 index 00000000..fb47d2d4 --- /dev/null +++ b/tests/PHPUnit/CustomTestCase/UsesPerFileAsPattern.php @@ -0,0 +1,7 @@ +in('*.php'); + +test('closure was bound to CustomTestCase', function () { + $this->assertCustomTrue(); +}); From aa9fe351a6a832453ebec031af9a3590be75b6b1 Mon Sep 17 00:00:00 2001 From: Mohammad Zahed Date: Sat, 10 Jun 2023 18:00:46 +0300 Subject: [PATCH 3/5] fix tests and static type check error --- src/PendingCalls/UsesCall.php | 2 +- .../InnerFolder}/UsesPerDirectoryAsPattern.php | 2 -- .../CustomTestCase/{ => SubFolder2}/UsesPerFileAsPattern.php | 2 -- tests/Pest.php | 5 +++++ 4 files changed, 6 insertions(+), 5 deletions(-) rename tests/PHPUnit/CustomTestCase/{ => SubFolder/InnerFolder}/UsesPerDirectoryAsPattern.php (60%) rename tests/PHPUnit/CustomTestCase/{ => SubFolder2}/UsesPerFileAsPattern.php (60%) diff --git a/src/PendingCalls/UsesCall.php b/src/PendingCalls/UsesCall.php index 8dfd9289..00267afb 100644 --- a/src/PendingCalls/UsesCall.php +++ b/src/PendingCalls/UsesCall.php @@ -84,7 +84,7 @@ final class UsesCall }, $targets); $this->targets = array_reduce($targets, function (array $accumulator, string $target): array { - if ($matches = glob($target)) { + if (($matches = glob($target)) != false) { foreach ($matches as $file) { $accumulator[] = (string) realpath($file); } diff --git a/tests/PHPUnit/CustomTestCase/UsesPerDirectoryAsPattern.php b/tests/PHPUnit/CustomTestCase/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php similarity index 60% rename from tests/PHPUnit/CustomTestCase/UsesPerDirectoryAsPattern.php rename to tests/PHPUnit/CustomTestCase/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php index 5e8546f4..196fea3a 100644 --- a/tests/PHPUnit/CustomTestCase/UsesPerDirectoryAsPattern.php +++ b/tests/PHPUnit/CustomTestCase/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php @@ -1,7 +1,5 @@ in('../*/'); - test('closure was bound to CustomTestCase', function () { $this->assertCustomTrue(); }); diff --git a/tests/PHPUnit/CustomTestCase/UsesPerFileAsPattern.php b/tests/PHPUnit/CustomTestCase/SubFolder2/UsesPerFileAsPattern.php similarity index 60% rename from tests/PHPUnit/CustomTestCase/UsesPerFileAsPattern.php rename to tests/PHPUnit/CustomTestCase/SubFolder2/UsesPerFileAsPattern.php index fb47d2d4..196fea3a 100644 --- a/tests/PHPUnit/CustomTestCase/UsesPerFileAsPattern.php +++ b/tests/PHPUnit/CustomTestCase/SubFolder2/UsesPerFileAsPattern.php @@ -1,7 +1,5 @@ in('*.php'); - test('closure was bound to CustomTestCase', function () { $this->assertCustomTrue(); }); diff --git a/tests/Pest.php b/tests/Pest.php index 23daca74..80f3fc7b 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,9 +1,14 @@ in('PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder'); +uses(CustomTestCase::class)->in('PHPUnit/CustomTestCase/SubFolder/*/'); + +uses(CustomTestCase::class)->in('PHPUnit/CustomTestCase/SubFolder2/*AsPattern.php'); + uses()->group('integration')->in('Visual'); // NOTE: global test value container to be mutated and checked across files, as needed From 40fd06c0d0e54c124f42dbcf94025f91f27317dd Mon Sep 17 00:00:00 2001 From: Mohammad Zahed Date: Mon, 12 Jun 2023 12:38:51 +0300 Subject: [PATCH 4/5] Update src/PendingCalls/UsesCall.php Co-authored-by: Owen Voke --- src/PendingCalls/UsesCall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PendingCalls/UsesCall.php b/src/PendingCalls/UsesCall.php index 00267afb..eabd5de9 100644 --- a/src/PendingCalls/UsesCall.php +++ b/src/PendingCalls/UsesCall.php @@ -84,7 +84,7 @@ final class UsesCall }, $targets); $this->targets = array_reduce($targets, function (array $accumulator, string $target): array { - if (($matches = glob($target)) != false) { + if (($matches = glob($target)) !== false) { foreach ($matches as $file) { $accumulator[] = (string) realpath($file); } From 801346b894f7e06875b75b40e32ce8a2071e4a15 Mon Sep 17 00:00:00 2001 From: Mohammad Zahed Date: Mon, 12 Jun 2023 12:53:27 +0300 Subject: [PATCH 5/5] move tests to GlobPatternTests folder and add comments for test cases --- .../SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php | 0 .../SubFolder2/UsesPerFileAsPattern.php | 0 tests/Pest.php | 6 ++++-- 3 files changed, 4 insertions(+), 2 deletions(-) rename tests/PHPUnit/{CustomTestCase => GlobPatternTests}/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php (100%) rename tests/PHPUnit/{CustomTestCase => GlobPatternTests}/SubFolder2/UsesPerFileAsPattern.php (100%) diff --git a/tests/PHPUnit/CustomTestCase/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php b/tests/PHPUnit/GlobPatternTests/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php similarity index 100% rename from tests/PHPUnit/CustomTestCase/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php rename to tests/PHPUnit/GlobPatternTests/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php diff --git a/tests/PHPUnit/CustomTestCase/SubFolder2/UsesPerFileAsPattern.php b/tests/PHPUnit/GlobPatternTests/SubFolder2/UsesPerFileAsPattern.php similarity index 100% rename from tests/PHPUnit/CustomTestCase/SubFolder2/UsesPerFileAsPattern.php rename to tests/PHPUnit/GlobPatternTests/SubFolder2/UsesPerFileAsPattern.php diff --git a/tests/Pest.php b/tests/Pest.php index 80f3fc7b..5105219b 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -5,9 +5,11 @@ use Tests\CustomTestCaseInSubFolders\SubFolder\SubFolder\CustomTestCaseInSubFold uses(CustomTestCaseInSubFolder::class)->in('PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder'); -uses(CustomTestCase::class)->in('PHPUnit/CustomTestCase/SubFolder/*/'); +// test case for all the directories inside PHPUnit/GlobPatternTests/SubFolder/ +uses(CustomTestCase::class)->in('PHPUnit/GlobPatternTests/SubFolder/*/'); -uses(CustomTestCase::class)->in('PHPUnit/CustomTestCase/SubFolder2/*AsPattern.php'); +// test case for all the files that end with AsPattern.php inside PHPUnit/GlobPatternTests/SubFolder2/ +uses(CustomTestCase::class)->in('PHPUnit/GlobPatternTests/SubFolder2/*AsPattern.php'); uses()->group('integration')->in('Visual');