Skip to content

Commit e4697bf

Browse files
committed
test: optimize AutoReview tests
1 parent 279eae2 commit e4697bf

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

.github/workflows/reusable-serviceless-phpunit-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
7777
with:
7878
persist-credentials: false
79+
fetch-depth: 0
7980

8081
- name: Setup PHP
8182
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0

.github/workflows/test-random-execution.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ jobs:
169169
170170
- name: Checkout
171171
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
172+
with:
173+
persist-credentials: false
174+
fetch-depth: 0
172175

173176
- name: Setup PHP ${{ matrix.php-version }}
174177
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0

tests/system/AutoReview/FrameworkCodeTest.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,9 @@ private static function getTestClasses(): array
107107

108108
$testClasses = array_map(
109109
static function (SplFileInfo $file) use ($directory): string {
110-
$relativePath = substr_replace(
111-
$file->getPathname(),
112-
'',
113-
0,
114-
strlen($directory),
115-
);
116-
$relativePath = substr_replace(
117-
$relativePath,
118-
'',
119-
strlen($relativePath) - strlen(DIRECTORY_SEPARATOR . $file->getBasename()),
120-
);
110+
$relativePath = substr($file->getPathname(), strlen($directory));
111+
$separatorPos = strrpos($relativePath, DIRECTORY_SEPARATOR);
112+
$relativePath = $separatorPos === false ? '' : substr($relativePath, 0, $separatorPos);
121113

122114
return sprintf(
123115
'CodeIgniter\\%s%s%s',
@@ -128,17 +120,15 @@ static function (SplFileInfo $file) use ($directory): string {
128120
},
129121
array_filter(
130122
iterator_to_array($iterator, false),
123+
// Filename-based heuristic: avoids the is_subclass_of() cold-autoload issue
124+
// by only considering files that end with "Test.php" or "TestCase.php".
131125
static fn (SplFileInfo $file): bool => $file->isFile()
126+
&& (str_ends_with($file->getBasename(), 'Test.php') || str_ends_with($file->getBasename(), 'TestCase.php'))
132127
&& ! str_contains($file->getPathname(), DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR)
133128
&& ! str_contains($file->getPathname(), DIRECTORY_SEPARATOR . 'Views' . DIRECTORY_SEPARATOR),
134129
),
135130
);
136131

137-
$testClasses = array_filter(
138-
$testClasses,
139-
static fn (string $class): bool => is_subclass_of($class, TestCase::class),
140-
);
141-
142132
sort($testClasses);
143133

144134
self::$testClasses = $testClasses;

0 commit comments

Comments
 (0)