From e39c3bde6c7146ea3bbceda6c38962a0ebbf692f Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 9 Oct 2026 14:16:13 -0400 Subject: [PATCH 1/4] Fix test suite Add a PHPUnit config so the suite runs, and update the integration tests to run the command non-interactively and assert on exit codes instead of exceptions. Co-Authored-By: Claude Opus 5.5 --- .gitignore | 1 + phpunit.xml.dist | 11 +++++++++ tests/NewCommandIntegrationTest.php | 37 +++++------------------------ 3 files changed, 18 insertions(+), 31 deletions(-) create mode 100644 phpunit.xml.dist diff --git a/.gitignore b/.gitignore index 37a78ec..7433203 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor .DS_Store composer.lock +.phpunit.result.cache diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..872e1be --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,11 @@ + + + + + tests + + + diff --git a/tests/NewCommandIntegrationTest.php b/tests/NewCommandIntegrationTest.php index bad85ed..342b039 100644 --- a/tests/NewCommandIntegrationTest.php +++ b/tests/NewCommandIntegrationTest.php @@ -3,7 +3,6 @@ namespace Statamic\Cli\Tests; use PHPUnit\Framework\TestCase; -use RuntimeException; use Statamic\Cli\NewCommand; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; @@ -74,9 +73,7 @@ public function it_fails_if_application_folder_already_exists() { mkdir($this->appPath()); - $this->assertRuntimeException(function () { - $this->scaffoldNewApp(); - }); + $this->assertSame(1, $this->scaffoldNewApp()); $this->assertFileExists($this->appPath()); $this->assertFileNotExists($this->appPath('vendor')); @@ -102,9 +99,7 @@ public function it_overwrites_application_when_using_force_option() /** @test */ public function it_fails_if_using_force_option_to_cwd() { - $this->assertRuntimeException(function () { - $this->scaffoldNewApp(['name' => '.', '--force' => true]); - }); + $this->assertSame(1, $this->scaffoldNewApp(['name' => '.', '--force' => true])); $this->assertAppNotExists(); } @@ -112,9 +107,7 @@ public function it_fails_if_using_force_option_to_cwd() /** @test */ public function it_fails_if_invalid_starter_kit_repo_is_passed() { - $this->assertRuntimeException(function () { - $this->scaffoldNewApp(['starter-kit' => 'not-a-valid-repo']); - }); + $this->assertSame(1, $this->scaffoldNewApp(['starter-kit' => 'not-a-valid-repo'])); $this->assertAppNotExists(); } @@ -122,26 +115,11 @@ public function it_fails_if_invalid_starter_kit_repo_is_passed() /** @test */ public function it_fails_when_there_is_starter_kit_error_but_leaves_base_installation() { - $this->assertRuntimeException(function () { - $this->scaffoldNewApp(['starter-kit' => 'statamic/not-an-actual-starter-kit']); - }); + $this->assertSame(1, $this->scaffoldNewApp(['starter-kit' => 'statamic/not-an-actual-starter-kit'])); $this->assertBasicAppScaffolded(); } - protected function assertRuntimeException($callback) - { - $error = false; - - try { - $callback(); - } catch (RuntimeException $exception) { - $error = true; - } - - $this->assertTrue($error); - } - protected function clearScaffoldDirectory() { if (file_exists($this->scaffoldDirectory)) { @@ -170,11 +148,9 @@ protected function scaffoldNewApp($args = []) $tester = new CommandTester($app->find('new')); - $args = array_merge(['name' => $this->scaffoldName], $args); - - $statusCode = $tester->execute($args); + $args = array_merge(['name' => $this->scaffoldName, '--no-interaction' => true], $args); - return $statusCode; + return $tester->execute($args, ['interactive' => false]); } protected function assertBasicAppScaffolded() @@ -186,7 +162,6 @@ protected function assertBasicAppScaffolded() $envFile = file_get_contents($this->appPath('.env')); $this->assertStringContainsString('APP_URL=http://my-app.test', $envFile); - $this->assertStringContainsString('DB_DATABASE=my_app', $envFile); } protected function assertAppNotExists() From 37793d1350e9a48c6a797025280f2fdca6cb92e1 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 9 Oct 2026 14:16:13 -0400 Subject: [PATCH 2/4] Add tests workflow Co-Authored-By: Claude Opus 5.5 --- .github/workflows/tests.yml | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..2544265 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,46 @@ +name: Tests + +on: + push: + branches: + - master + - '*.x' + pull_request: + +permissions: {} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + tests: + name: PHP ${{ matrix.php }} - ${{ matrix.stability }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php: ['8.2', '8.3', '8.4', '8.5'] + stability: [prefer-lowest, prefer-stable] + + steps: + - name: Checkout code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Setup PHP + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: ${{ matrix.php }} + extensions: pdo_sqlite + coverage: none + + - name: Install dependencies + env: + STABILITY: ${{ matrix.stability }} + run: composer update --"$STABILITY" --prefer-dist --no-interaction --no-progress + + - name: Run tests + run: vendor/bin/phpunit From 44b692c3b8dc038994316c22e92f3bca9b463d32 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 9 Oct 2026 14:21:56 -0400 Subject: [PATCH 3/4] Add aggregate PHP tests check Co-Authored-By: Claude Opus 5.5 --- .github/workflows/tests.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2544265..4840d26 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,9 +14,11 @@ concurrency: cancel-in-progress: true jobs: - tests: + php-tests: name: PHP ${{ matrix.php }} - ${{ matrix.stability }} runs-on: ubuntu-latest + permissions: + contents: read strategy: fail-fast: false @@ -44,3 +46,15 @@ jobs: - name: Run tests run: vendor/bin/phpunit + + php-tests-result: + name: PHP tests + runs-on: ubuntu-latest + needs: [php-tests] + if: always() + permissions: {} + + steps: + - name: Fail if any job failed + if: needs.php-tests.result != 'success' && needs.php-tests.result != 'skipped' + run: exit 1 From 53794bc9c25e98fa435c990367e4124ba09f567e Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 9 Oct 2026 14:36:22 -0400 Subject: [PATCH 4/4] Don't pass --no-ansi and --quiet to rm and rd GNU rm rejects unknown options, so --force failed on Linux whenever output wasn't decorated or --quiet was used. Co-Authored-By: Claude Opus 5.5 --- src/Concerns/RunsCommands.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Concerns/RunsCommands.php b/src/Concerns/RunsCommands.php index aceea9c..e61fa06 100644 --- a/src/Concerns/RunsCommands.php +++ b/src/Concerns/RunsCommands.php @@ -38,6 +38,10 @@ protected function runCommands(array $commands, ?string $workingPath = null, boo return $value; } + if (str_starts_with($value, 'rm ') || str_starts_with($value, 'rd ')) { + return $value; + } + return $value.' --no-ansi'; }, $commands); } @@ -52,6 +56,10 @@ protected function runCommands(array $commands, ?string $workingPath = null, boo return $value; } + if (str_starts_with($value, 'rm ') || str_starts_with($value, 'rd ')) { + return $value; + } + return $value.' --quiet'; }, $commands); }