Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
.DS_Store
composer.lock
.phpunit.result.cache
11 changes: 11 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
8 changes: 8 additions & 0 deletions src/Concerns/RunsCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
37 changes: 6 additions & 31 deletions tests/NewCommandIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
Expand All @@ -102,46 +99,27 @@ 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();
}

/** @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();
}

/** @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)) {
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Loading