diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9b8a824e84..987a7e3ade 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,6 +39,7 @@ jobs: POSTGRES_USER: postgres POSTGRES_PASSWORD: password POSTGRES_DB: testing + POSTGRES_HOST_AUTH_METHOD: trust ports: - 5432:5432 options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3 @@ -75,7 +76,11 @@ jobs: echo "Waiting for Postgres ($i) ..." && sleep 2 done echo "Postgres did not become ready in time" && exit 1 - - name: Execute tests - run: ./vendor/bin/pest --configuration=phpunit.${{ matrix.db }}.xml + - name: Execute tests (parallel) + run: ./vendor/bin/pest --configuration=phpunit.${{ matrix.db }}.xml --parallel --exclude-group=commands + env: + DB_PASSWORD: password + - name: Execute command tests (serial) + run: ./vendor/bin/pest --configuration=phpunit.${{ matrix.db }}.xml --group=commands env: DB_PASSWORD: password diff --git a/composer.json b/composer.json index 2123870ba8..b11f9be822 100644 --- a/composer.json +++ b/composer.json @@ -83,10 +83,13 @@ ], "pint": "pint --config pint-strict-imports.json", "rector": "rector", - "test:pest": "pest --parallel", - "test:sqlite": "pest --configuration=phpunit.sqlite.xml --parallel", - "test:mysql": "pest --configuration=phpunit.mysql.xml", - "test:pgsql": "pest --configuration=phpunit.pgsql.xml", + "test:pest": "pest --parallel --exclude-group=commands", + "test:sqlite": "pest --configuration=phpunit.sqlite.xml --parallel --exclude-group=commands", + "test:mysql": "pest --configuration=phpunit.mysql.xml --parallel --exclude-group=commands", + "test:pgsql": "pest --configuration=phpunit.pgsql.xml --parallel --exclude-group=commands", + "test:commands:sqlite": "pest --configuration=phpunit.sqlite.xml --group=commands", + "test:commands:mysql": "pest --configuration=phpunit.mysql.xml --group=commands", + "test:commands:pgsql": "pest --configuration=phpunit.pgsql.xml --group=commands", "test:all-databases": [ "@test:sqlite", "@test:mysql", @@ -95,6 +98,7 @@ "test:phpstan": "phpstan analyse", "test": [ "@test:sqlite", + "@test:commands:sqlite", "@test:phpstan" ] }, diff --git a/tests/src/Forms/Commands/MakeFieldCommandTest.php b/tests/src/Forms/Commands/MakeFieldCommandTest.php index d1ad9a81bb..92532a36fa 100644 --- a/tests/src/Forms/Commands/MakeFieldCommandTest.php +++ b/tests/src/Forms/Commands/MakeFieldCommandTest.php @@ -1,16 +1,10 @@ skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +uses(TestCase::class)->group('commands'); it('can generate a field class', function (): void { $this->withoutMockingConsoleOutput(); diff --git a/tests/src/Forms/Commands/MakeFormCommandTest.php b/tests/src/Forms/Commands/MakeFormCommandTest.php index b06f4e407f..189450de19 100644 --- a/tests/src/Forms/Commands/MakeFormCommandTest.php +++ b/tests/src/Forms/Commands/MakeFormCommandTest.php @@ -1,16 +1,14 @@ group('commands'); beforeEach(function (): void { $this->withoutMockingConsoleOutput(); -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a form schema class', function (): void { $this->artisan('make:filament-form', [ diff --git a/tests/src/Forms/Commands/MakeLivewireFormCommandTest.php b/tests/src/Forms/Commands/MakeLivewireFormCommandTest.php index 700c37d04c..f4b1858c4e 100644 --- a/tests/src/Forms/Commands/MakeLivewireFormCommandTest.php +++ b/tests/src/Forms/Commands/MakeLivewireFormCommandTest.php @@ -1,16 +1,14 @@ group('commands'); beforeEach(function (): void { $this->withoutMockingConsoleOutput(); -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a Livewire form component', function (): void { $this->artisan('make:filament-livewire-form', [ diff --git a/tests/src/Infolists/Commands/MakeEntryCommandTest.php b/tests/src/Infolists/Commands/MakeEntryCommandTest.php index 9ec087dc27..6cd20e836d 100644 --- a/tests/src/Infolists/Commands/MakeEntryCommandTest.php +++ b/tests/src/Infolists/Commands/MakeEntryCommandTest.php @@ -1,16 +1,10 @@ skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +uses(TestCase::class)->group('commands'); it('can generate an entry class', function (): void { $this->withoutMockingConsoleOutput(); diff --git a/tests/src/Panels/Commands/Legacy/LegacyMakeClusterCommandTest.php b/tests/src/Panels/Commands/Legacy/LegacyMakeClusterCommandTest.php index bcd0721bc3..29c48458b5 100644 --- a/tests/src/Panels/Commands/Legacy/LegacyMakeClusterCommandTest.php +++ b/tests/src/Panels/Commands/Legacy/LegacyMakeClusterCommandTest.php @@ -2,11 +2,10 @@ use Filament\Support\Commands\FileGenerators\FileGenerationFlag; use Filament\Tests\TestCase; -use Illuminate\Support\Arr; use function PHPUnit\Framework\assertFileExists; -uses(TestCase::class); +uses(TestCase::class)->group('commands'); beforeEach(function (): void { config()->set('filament.file_generation.flags', [ @@ -14,8 +13,7 @@ beforeEach(function (): void { ]); $this->withoutMockingConsoleOutput(); -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a cluster class', function (): void { $this->artisan('make:filament-cluster', [ diff --git a/tests/src/Panels/Commands/Legacy/LegacyMakePageCommandTest.php b/tests/src/Panels/Commands/Legacy/LegacyMakePageCommandTest.php index 4f6df9c06c..343f64fdbb 100644 --- a/tests/src/Panels/Commands/Legacy/LegacyMakePageCommandTest.php +++ b/tests/src/Panels/Commands/Legacy/LegacyMakePageCommandTest.php @@ -6,13 +6,12 @@ use Filament\Support\Commands\FileGenerators\FileGenerationFlag; use Filament\Tests\TestCase; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Support\Arr; use Illuminate\Testing\PendingCommand; use function PHPUnit\Framework\assertFileDoesNotExist; use function PHPUnit\Framework\assertFileExists; -uses(TestCase::class); +uses(TestCase::class)->group('commands'); beforeEach(function (): void { config()->set('filament.file_generation.flags', [ @@ -24,8 +23,7 @@ beforeEach(function (): void { ]); MakePageCommand::$shouldCheckModelsForSoftDeletes = false; -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a page class', function (): void { $this->withoutMockingConsoleOutput(); diff --git a/tests/src/Panels/Commands/Legacy/LegacyMakeRelationManagerCommandTest.php b/tests/src/Panels/Commands/Legacy/LegacyMakeRelationManagerCommandTest.php index c969c97740..2c75a39ae0 100644 --- a/tests/src/Panels/Commands/Legacy/LegacyMakeRelationManagerCommandTest.php +++ b/tests/src/Panels/Commands/Legacy/LegacyMakeRelationManagerCommandTest.php @@ -4,11 +4,10 @@ use Filament\Commands\MakeRelationManagerCommand; use Filament\Facades\Filament; use Filament\Support\Commands\FileGenerators\FileGenerationFlag; use Filament\Tests\TestCase; -use Illuminate\Support\Arr; use function PHPUnit\Framework\assertFileExists; -uses(TestCase::class); +uses(TestCase::class)->group('commands'); beforeEach(function (): void { config()->set('filament.file_generation.flags', [ @@ -52,8 +51,7 @@ beforeEach(function (): void { ]; MakeRelationManagerCommand::$shouldCheckModelsForSoftDeletes = false; -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a relation manager', function (): void { $this->artisan('make:filament-relation-manager', [ diff --git a/tests/src/Panels/Commands/Legacy/LegacyMakeResourceCommandTest.php b/tests/src/Panels/Commands/Legacy/LegacyMakeResourceCommandTest.php index 149da79f29..7dc899bc3f 100644 --- a/tests/src/Panels/Commands/Legacy/LegacyMakeResourceCommandTest.php +++ b/tests/src/Panels/Commands/Legacy/LegacyMakeResourceCommandTest.php @@ -3,11 +3,10 @@ use Filament\Commands\MakeResourceCommand; use Filament\Support\Commands\FileGenerators\FileGenerationFlag; use Filament\Tests\TestCase; -use Illuminate\Support\Arr; use function PHPUnit\Framework\assertFileExists; -uses(TestCase::class); +uses(TestCase::class)->group('commands'); beforeEach(function (): void { config()->set('filament.file_generation.flags', [ @@ -20,8 +19,7 @@ beforeEach(function (): void { $this->withoutMockingConsoleOutput(); MakeResourceCommand::$shouldCheckModelsForSoftDeletes = false; -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a resource class', function (): void { $this->artisan('make:filament-resource', [ diff --git a/tests/src/Panels/Commands/Legacy/LegacyMakeSettingsPageCommandTest.php b/tests/src/Panels/Commands/Legacy/LegacyMakeSettingsPageCommandTest.php index 536ed0e67a..6a47431514 100644 --- a/tests/src/Panels/Commands/Legacy/LegacyMakeSettingsPageCommandTest.php +++ b/tests/src/Panels/Commands/Legacy/LegacyMakeSettingsPageCommandTest.php @@ -10,12 +10,11 @@ use DateTimeImmutable; use DateTimeInterface; use Filament\Support\Commands\FileGenerators\FileGenerationFlag; use Filament\Tests\TestCase; -use Illuminate\Support\Arr; use Spatie\LaravelSettings\Settings as BaseSettings; use function PHPUnit\Framework\assertFileExists; -uses(TestCase::class); +uses(TestCase::class)->group('commands'); beforeEach(function (): void { config()->set('filament.file_generation.flags', [ @@ -24,8 +23,7 @@ beforeEach(function (): void { ]); $this->withoutMockingConsoleOutput(); -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a page class', function (): void { $this->artisan('make:filament-settings-page', [ diff --git a/tests/src/Panels/Commands/MakeClusterCommandTest.php b/tests/src/Panels/Commands/MakeClusterCommandTest.php index f2fba06656..980d084610 100644 --- a/tests/src/Panels/Commands/MakeClusterCommandTest.php +++ b/tests/src/Panels/Commands/MakeClusterCommandTest.php @@ -1,16 +1,14 @@ group('commands'); beforeEach(function (): void { $this->withoutMockingConsoleOutput(); -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a cluster class', function (): void { $this->artisan('make:filament-cluster', [ diff --git a/tests/src/Panels/Commands/MakePageCommandTest.php b/tests/src/Panels/Commands/MakePageCommandTest.php index 0201f48a43..49c700af03 100644 --- a/tests/src/Panels/Commands/MakePageCommandTest.php +++ b/tests/src/Panels/Commands/MakePageCommandTest.php @@ -5,18 +5,16 @@ use Filament\Facades\Filament; use Filament\Tests\TestCase; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Support\Arr; use Illuminate\Testing\PendingCommand; use function PHPUnit\Framework\assertFileDoesNotExist; use function PHPUnit\Framework\assertFileExists; -uses(TestCase::class); +uses(TestCase::class)->group('commands'); beforeEach(function (): void { MakePageCommand::$shouldCheckModelsForSoftDeletes = false; -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a page class', function (): void { $this->withoutMockingConsoleOutput(); diff --git a/tests/src/Panels/Commands/MakeRelationManagerCommandTest.php b/tests/src/Panels/Commands/MakeRelationManagerCommandTest.php index 7cf495f035..ab308e310c 100644 --- a/tests/src/Panels/Commands/MakeRelationManagerCommandTest.php +++ b/tests/src/Panels/Commands/MakeRelationManagerCommandTest.php @@ -3,11 +3,10 @@ use Filament\Commands\MakeRelationManagerCommand; use Filament\Facades\Filament; use Filament\Tests\TestCase; -use Illuminate\Support\Arr; use function PHPUnit\Framework\assertFileExists; -uses(TestCase::class); +uses(TestCase::class)->group('commands'); beforeEach(function (): void { $this->withoutMockingConsoleOutput(); @@ -47,8 +46,7 @@ beforeEach(function (): void { ]; MakeRelationManagerCommand::$shouldCheckModelsForSoftDeletes = false; -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a relation manager', function (): void { $this->artisan('make:filament-relation-manager', [ diff --git a/tests/src/Panels/Commands/MakeResourceCommandTest.php b/tests/src/Panels/Commands/MakeResourceCommandTest.php index 55555c9eb3..fca876ed7d 100644 --- a/tests/src/Panels/Commands/MakeResourceCommandTest.php +++ b/tests/src/Panels/Commands/MakeResourceCommandTest.php @@ -3,19 +3,17 @@ use Filament\Commands\MakeResourceCommand; use Filament\Facades\Filament; use Filament\Tests\TestCase; -use Illuminate\Support\Arr; use function PHPUnit\Framework\assertFileDoesNotExist; use function PHPUnit\Framework\assertFileExists; -uses(TestCase::class); +uses(TestCase::class)->group('commands'); beforeEach(function (): void { $this->withoutMockingConsoleOutput(); MakeResourceCommand::$shouldCheckModelsForSoftDeletes = false; -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a resource class', function (): void { $this->artisan('make:filament-resource', [ diff --git a/tests/src/Panels/Commands/MakeSettingsPageCommandTest.php b/tests/src/Panels/Commands/MakeSettingsPageCommandTest.php index 5f87a45b5f..47dcc1e725 100644 --- a/tests/src/Panels/Commands/MakeSettingsPageCommandTest.php +++ b/tests/src/Panels/Commands/MakeSettingsPageCommandTest.php @@ -9,17 +9,15 @@ use DateTime; use DateTimeImmutable; use DateTimeInterface; use Filament\Tests\TestCase; -use Illuminate\Support\Arr; use Spatie\LaravelSettings\Settings as BaseSettings; use function PHPUnit\Framework\assertFileExists; -uses(TestCase::class); +uses(TestCase::class)->group('commands'); beforeEach(function (): void { $this->withoutMockingConsoleOutput(); -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a page class', function (): void { $this->artisan('make:filament-settings-page', [ diff --git a/tests/src/Schemas/Commands/MakeComponentCommandTest.php b/tests/src/Schemas/Commands/MakeComponentCommandTest.php index 8ea2059207..fe9b16fcaf 100644 --- a/tests/src/Schemas/Commands/MakeComponentCommandTest.php +++ b/tests/src/Schemas/Commands/MakeComponentCommandTest.php @@ -1,16 +1,10 @@ skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +uses(TestCase::class)->group('commands'); it('can generate a component class', function (): void { $this->withoutMockingConsoleOutput(); diff --git a/tests/src/Schemas/Commands/MakeLivewireSchemaCommandTest.php b/tests/src/Schemas/Commands/MakeLivewireSchemaCommandTest.php index 951f0f2453..ab87bc0193 100644 --- a/tests/src/Schemas/Commands/MakeLivewireSchemaCommandTest.php +++ b/tests/src/Schemas/Commands/MakeLivewireSchemaCommandTest.php @@ -1,16 +1,14 @@ group('commands'); beforeEach(function (): void { $this->withoutMockingConsoleOutput(); -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a Livewire schema component', function (): void { $this->artisan('make:filament-livewire-schema', [ diff --git a/tests/src/Schemas/Commands/MakeSchemaCommandTest.php b/tests/src/Schemas/Commands/MakeSchemaCommandTest.php index ce1887a3ed..5aeb47c208 100644 --- a/tests/src/Schemas/Commands/MakeSchemaCommandTest.php +++ b/tests/src/Schemas/Commands/MakeSchemaCommandTest.php @@ -1,16 +1,10 @@ skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +uses(TestCase::class)->group('commands'); it('can generate a schema class', function (): void { $this->withoutMockingConsoleOutput(); diff --git a/tests/src/Tables/Commands/MakeColumnCommandTest.php b/tests/src/Tables/Commands/MakeColumnCommandTest.php index 53f8e02622..21313fc54c 100644 --- a/tests/src/Tables/Commands/MakeColumnCommandTest.php +++ b/tests/src/Tables/Commands/MakeColumnCommandTest.php @@ -1,17 +1,11 @@ skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +uses(TestCase::class)->group('commands'); it('can generate a column class', function (): void { $this->withoutMockingConsoleOutput(); diff --git a/tests/src/Tables/Commands/MakeLivewireTableCommandTest.php b/tests/src/Tables/Commands/MakeLivewireTableCommandTest.php index 00908838c7..284bd6dafd 100644 --- a/tests/src/Tables/Commands/MakeLivewireTableCommandTest.php +++ b/tests/src/Tables/Commands/MakeLivewireTableCommandTest.php @@ -1,16 +1,14 @@ group('commands'); beforeEach(function (): void { $this->withoutMockingConsoleOutput(); -}) - ->skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +}); it('can generate a Livewire table component', function (): void { $this->artisan('make:filament-livewire-table', [ diff --git a/tests/src/Tables/Commands/MakeTableCommandTest.php b/tests/src/Tables/Commands/MakeTableCommandTest.php index c17370ed70..62cbe481bc 100644 --- a/tests/src/Tables/Commands/MakeTableCommandTest.php +++ b/tests/src/Tables/Commands/MakeTableCommandTest.php @@ -1,16 +1,10 @@ skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +uses(TestCase::class)->group('commands'); it('can generate a table class', function (): void { $this->withoutMockingConsoleOutput(); diff --git a/tests/src/TestCase.php b/tests/src/TestCase.php index 5c90f803d0..13e1c76e84 100644 --- a/tests/src/TestCase.php +++ b/tests/src/TestCase.php @@ -37,6 +37,7 @@ use Livewire\LivewireServiceProvider; use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase as BaseTestCase; use PDO; +use PDOException; use RyanChandler\BladeCaptureDirective\BladeCaptureDirectiveServiceProvider; abstract class TestCase extends BaseTestCase @@ -91,6 +92,11 @@ abstract class TestCase extends BaseTestCase __DIR__ . '/../resources/views', ]); + // Paratest sets TEST_TOKEN for each worker (0, 1, 2, etc.) + $testToken = env('TEST_TOKEN', ''); + $dbSuffix = $testToken !== '' ? "_{$testToken}" : ''; + $dbName = env('DB_DATABASE', 'testing') . $dbSuffix; + $app['config']->set('database.connections.sqlite', [ 'driver' => 'sqlite', 'database' => env('DB_DATABASE', ':memory:'), @@ -102,7 +108,7 @@ abstract class TestCase extends BaseTestCase 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('MYSQL_PORT', env('DB_PORT', '3306')), - 'database' => env('DB_DATABASE', 'testing'), + 'database' => $dbName, 'username' => env('MYSQL_USERNAME', env('DB_USERNAME', 'root')), 'password' => env('MYSQL_PASSWORD', env('DB_PASSWORD', '')), 'charset' => 'utf8mb4', @@ -121,7 +127,7 @@ abstract class TestCase extends BaseTestCase 'driver' => 'pgsql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('PGSQL_PORT', env('DB_PORT', '5432')), - 'database' => env('DB_DATABASE', 'testing'), + 'database' => $dbName, 'username' => env('PGSQL_USERNAME', env('DB_USERNAME', 'postgres')), 'password' => env('PGSQL_PASSWORD', env('DB_PASSWORD', '')), 'charset' => 'utf8', @@ -134,7 +140,42 @@ abstract class TestCase extends BaseTestCase ], ]); - $app['config']->set('database.default', env('DB_CONNECTION', 'testing')); + $connection = env('DB_CONNECTION', 'testing'); + + // Auto-create test databases for MySQL/PostgreSQL parallel workers + if ($dbSuffix !== '' && in_array($connection, ['mysql', 'pgsql'])) { + $this->ensureDatabaseExists($connection, $dbName, $app['config']->get("database.connections.{$connection}")); + } + + $app['config']->set('database.default', $connection); $app['config']->set('database.connections.testing', $app['config']->get('database.connections.sqlite')); } + + protected function ensureDatabaseExists(string $driver, string $dbName, array $config): void + { + try { + if ($driver === 'mysql') { + $pdo = new PDO( + "mysql:host={$config['host']};port={$config['port']}", + $config['username'], + $config['password'], + $config['options'] + ); + $pdo->exec("create database if not exists `{$dbName}` character set {$config['charset']} collate {$config['collation']}"); + } elseif ($driver === 'pgsql') { + $pdo = new PDO( + "pgsql:host={$config['host']};port={$config['port']};dbname=postgres", + $config['username'], + $config['password'], + $config['options'] + ); + $result = $pdo->query("select 1 from pg_database where datname = '{$dbName}'"); + if ($result->fetchColumn() === false) { + $pdo->exec("create database \"{$dbName}\""); + } + } + } catch (PDOException) { + // Database might already exist or connection failed - let it fail later with a clearer error + } + } } diff --git a/tests/src/Widgets/Commands/MakeWidgetCommandTest.php b/tests/src/Widgets/Commands/MakeWidgetCommandTest.php index 52ce3ec475..b080b6e997 100644 --- a/tests/src/Widgets/Commands/MakeWidgetCommandTest.php +++ b/tests/src/Widgets/Commands/MakeWidgetCommandTest.php @@ -1,16 +1,10 @@ skip((bool) Arr::get($_SERVER, 'PARATEST'), 'File generation tests cannot be run in parallel as they would share a filesystem and have the potential to conflict with each other.'); +uses(TestCase::class)->group('commands'); it('can generate a custom widget class', function (): void { $this->withoutMockingConsoleOutput();