From 8aa77004aa0f1031e774a202150f3b6edbd2a74c Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 21 Apr 2026 20:20:38 +0800 Subject: [PATCH] test: optimize AutoReview tests --- .../reusable-serviceless-phpunit-test.yml | 1 + .github/workflows/test-random-execution.yml | 3 +++ .../AutoReview/CreateNewChangelogTest.php | 17 -------------- tests/system/AutoReview/FrameworkCodeTest.php | 22 +++++-------------- 4 files changed, 10 insertions(+), 33 deletions(-) diff --git a/.github/workflows/reusable-serviceless-phpunit-test.yml b/.github/workflows/reusable-serviceless-phpunit-test.yml index af205cda26f0..c59592f481ad 100644 --- a/.github/workflows/reusable-serviceless-phpunit-test.yml +++ b/.github/workflows/reusable-serviceless-phpunit-test.yml @@ -76,6 +76,7 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false + fetch-depth: 0 - name: Setup PHP uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 diff --git a/.github/workflows/test-random-execution.yml b/.github/workflows/test-random-execution.yml index 9785ee9efe35..5a1f9609a613 100644 --- a/.github/workflows/test-random-execution.yml +++ b/.github/workflows/test-random-execution.yml @@ -169,6 +169,9 @@ jobs: - name: Checkout uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + fetch-depth: 0 - name: Setup PHP ${{ matrix.php-version }} uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 diff --git a/tests/system/AutoReview/CreateNewChangelogTest.php b/tests/system/AutoReview/CreateNewChangelogTest.php index b6a89e047f88..21911a0e7293 100644 --- a/tests/system/AutoReview/CreateNewChangelogTest.php +++ b/tests/system/AutoReview/CreateNewChangelogTest.php @@ -27,23 +27,6 @@ final class CreateNewChangelogTest extends TestCase { private string $currentVersion; - public static function setUpBeforeClass(): void - { - parent::setUpBeforeClass(); - - if (getenv('GITHUB_ACTIONS') !== false) { - exec('git fetch --unshallow 2>&1', $output, $exitCode); - exec('git fetch --tags 2>&1', $output, $exitCode); - - if ($exitCode !== 0) { - self::fail(sprintf( - "Failed to fetch git history and tags.\nOutput: %s", - implode("\n", $output), - )); - } - } - } - protected function setUp(): void { parent::setUp(); diff --git a/tests/system/AutoReview/FrameworkCodeTest.php b/tests/system/AutoReview/FrameworkCodeTest.php index 137839b024e5..de515fffebf6 100644 --- a/tests/system/AutoReview/FrameworkCodeTest.php +++ b/tests/system/AutoReview/FrameworkCodeTest.php @@ -107,17 +107,9 @@ private static function getTestClasses(): array $testClasses = array_map( static function (SplFileInfo $file) use ($directory): string { - $relativePath = substr_replace( - $file->getPathname(), - '', - 0, - strlen($directory), - ); - $relativePath = substr_replace( - $relativePath, - '', - strlen($relativePath) - strlen(DIRECTORY_SEPARATOR . $file->getBasename()), - ); + $relativePath = substr($file->getPathname(), strlen($directory)); + $separatorPos = strrpos($relativePath, DIRECTORY_SEPARATOR); + $relativePath = $separatorPos === false ? '' : substr($relativePath, 0, $separatorPos); return sprintf( 'CodeIgniter\\%s%s%s', @@ -128,17 +120,15 @@ static function (SplFileInfo $file) use ($directory): string { }, array_filter( iterator_to_array($iterator, false), + // Filename-based heuristic: avoids the is_subclass_of() cold-autoload issue + // by only considering files that end with "Test.php" or "TestCase.php". static fn (SplFileInfo $file): bool => $file->isFile() + && (str_ends_with($file->getBasename(), 'Test.php') || str_ends_with($file->getBasename(), 'TestCase.php')) && ! str_contains($file->getPathname(), DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR) && ! str_contains($file->getPathname(), DIRECTORY_SEPARATOR . 'Views' . DIRECTORY_SEPARATOR), ), ); - $testClasses = array_filter( - $testClasses, - static fn (string $class): bool => is_subclass_of($class, TestCase::class), - ); - sort($testClasses); self::$testClasses = $testClasses;