diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..4840d26 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,60 @@ +name: Tests + +on: + push: + branches: + - master + - '*.x' + pull_request: + +permissions: {} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + php-tests: + name: PHP ${{ matrix.php }} - ${{ matrix.stability }} + runs-on: ubuntu-latest + permissions: + contents: read + + 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 + + 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 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/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); } 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()