diff --git a/composer.json b/composer.json index 5884c7b..e302315 100644 --- a/composer.json +++ b/composer.json @@ -53,8 +53,7 @@ "ext-pdo": "*", "mockery/mockery": "^1.3.1", "orchestra/testbench": "^8.0 || ^9.0", - "pestphp/pest": "^2.34", - "pestphp/pest-plugin-laravel": "^2.3" + "pestphp/pest": "^2.34" }, "minimum-stability": "stable", "prefer-stable": true, diff --git a/tests/Helpers/string.php b/tests/Helpers/string.php index 5807f63..5b87b84 100644 --- a/tests/Helpers/string.php +++ b/tests/Helpers/string.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use Illuminate\Database\Console\DumpCommand; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Str; use function PHPUnit\Framework\assertSame; @@ -11,3 +13,20 @@ return $this; }); + +expect()->extend('toBeDumped', function (int $count) { + $migrations = is_array($table = config('database.migrations')) ? $table['table'] : $table; + + config()->set('database.schema.tables', [$migrations]); + + $path = dumpStoragePath(); + + Artisan::call(DumpCommand::class, ['--path' => $path]); + + expect(file_get_contents($path)) + ->toBeContainsMigrations() + ->toBeWordsCount(sprintf($this->value, $migrations), $count) + ->notToBeDataContains('foo') + ->notToBeDataContains('bar') + ->notToBeDataContains('baz'); +}); diff --git a/tests/Unit/Dumps/DumpTest.php b/tests/Unit/Dumps/DumpTest.php index e68d5fa..3f7820e 100644 --- a/tests/Unit/Dumps/DumpTest.php +++ b/tests/Unit/Dumps/DumpTest.php @@ -1,8 +1,7 @@ $path])->run(); + Artisan::call(DumpCommand::class, ['--path' => $path]); expect(file_get_contents($path)) ->toBeContainsMigrations() diff --git a/tests/Unit/Migrations/MySQLTest.php b/tests/Unit/Migrations/MySQLTest.php index 5c3bf97..bd7fe47 100644 --- a/tests/Unit/Migrations/MySQLTest.php +++ b/tests/Unit/Migrations/MySQLTest.php @@ -1,22 +1,5 @@ set('database.schema.tables', [$migrations]); - - $path = dumpStoragePath(); - - artisan(DumpCommand::class, ['--path' => $path])->run(); - - expect(file_get_contents($path)) - ->toBeContainsMigrations() - ->toBeWordsCount("INSERT INTO `$migrations`", 3) - ->notToBeDataContains('foo') - ->notToBeDataContains('bar') - ->notToBeDataContains('baz'); + expect('INSERT INTO `%s`')->toBeDumped(3); })->group('MySQL'); diff --git a/tests/Unit/Migrations/PostgresTest.php b/tests/Unit/Migrations/PostgresTest.php index 08ffa15..9d913e8 100644 --- a/tests/Unit/Migrations/PostgresTest.php +++ b/tests/Unit/Migrations/PostgresTest.php @@ -1,22 +1,5 @@ set('database.schema.tables', [$migrations]); - - $path = dumpStoragePath(); - - artisan(DumpCommand::class, ['--path' => $path])->run(); - - expect(file_get_contents($path)) - ->toBeContainsMigrations() - ->toBeWordsCount("COPY public.$migrations", 1) - ->notToBeDataContains('foo') - ->notToBeDataContains('bar') - ->notToBeDataContains('baz'); + expect('COPY public.%s')->toBeDumped(1); })->group('Postgres'); diff --git a/tests/Unit/Migrations/SQLiteTest.php b/tests/Unit/Migrations/SQLiteTest.php index 2549a61..dde27d9 100644 --- a/tests/Unit/Migrations/SQLiteTest.php +++ b/tests/Unit/Migrations/SQLiteTest.php @@ -1,22 +1,5 @@ set('database.schema.tables', [$migrations]); - - $path = dumpStoragePath(); - - artisan(DumpCommand::class, ['--path' => $path])->run(); - - expect(file_get_contents($path)) - ->toBeContainsMigrations() - ->toBeWordsCount("INSERT INTO $migrations", 3) - ->notToBeDataContains('foo') - ->notToBeDataContains('bar') - ->notToBeDataContains('baz'); + expect('INSERT INTO %s')->toBeDumped(3); })->group('SQLite');