From f7932effba39ffc23e1372ab8d2cfae73666cf08 Mon Sep 17 00:00:00 2001 From: Bas Date: Sun, 1 Dec 2024 14:02:20 +0100 Subject: [PATCH] feat: Added support for dropAnalyzers, dropGraphs and dropAll to TestCase --- .../CanConfigureMigrationCommands.php | 59 +++++++++++++++++++ src/Testing/DatabaseMigrations.php | 28 +++------ src/Testing/DatabaseTruncation.php | 27 +++------ src/Testing/RefreshDatabase.php | 8 +++ tests/TestCase.php | 2 +- tests/Testing/DatabaseTruncationTest.php | 1 - 6 files changed, 83 insertions(+), 42 deletions(-) create mode 100644 src/Testing/Concerns/CanConfigureMigrationCommands.php diff --git a/src/Testing/Concerns/CanConfigureMigrationCommands.php b/src/Testing/Concerns/CanConfigureMigrationCommands.php new file mode 100644 index 0000000..40d46b4 --- /dev/null +++ b/src/Testing/Concerns/CanConfigureMigrationCommands.php @@ -0,0 +1,59 @@ +|string> + */ + protected function setMigrationPaths() + { + $migrationSettings = []; + + if (property_exists($this, 'realPath')) { + $migrationSettings['--realpath'] = $this->realPath ?? false; + } + + if (property_exists($this, 'migrationPaths')) { + $migrationSettings['--path'] = $this->migrationPaths; + } + + return $migrationSettings; + } + + /** + * Determine if custom analyzers should be dropped when refreshing the database. + * + * @return bool + */ + protected function shouldDropAnalyzers() + { + return property_exists($this, 'dropAnalyzers') ? $this->dropAnalyzers : false; + } + + /** + * Determine if graphs should be dropped when refreshing the database. + * + * @return bool + */ + protected function shouldDropGraphs() + { + return property_exists($this, 'dropGraphs') ? $this->dropGraphs : false; + } + + + /** + * Determine if all analyzers, graphs and views should be dropped when refreshing the database. + * + * @return bool + */ + protected function shouldDropAll() + { + return property_exists($this, 'dropAll') ? $this->dropAll : false; + } +} diff --git a/src/Testing/DatabaseMigrations.php b/src/Testing/DatabaseMigrations.php index aaedcac..d5cf3f3 100644 --- a/src/Testing/DatabaseMigrations.php +++ b/src/Testing/DatabaseMigrations.php @@ -5,14 +5,19 @@ namespace LaravelFreelancerNL\Aranguent\Testing; use Illuminate\Foundation\Testing\DatabaseMigrations as IlluminateDatabaseMigrations; +use LaravelFreelancerNL\Aranguent\Testing\Concerns\CanConfigureMigrationCommands; trait DatabaseMigrations { use IlluminateDatabaseMigrations; + use CanConfigureMigrationCommands; + /** * The parameters that should be used when running "migrate:fresh". * + * Duplicate code because CanConfigureMigrationCommands has a conflict otherwise. + * * @return array */ protected function migrateFreshUsing() @@ -21,8 +26,11 @@ protected function migrateFreshUsing() $results = array_merge( [ + '--drop-analyzers' => $this->shouldDropAnalyzers(), + '--drop-graphs' => $this->shouldDropGraphs(), '--drop-views' => $this->shouldDropViews(), '--drop-types' => $this->shouldDropTypes(), + '--drop-all' => $this->shouldDropAll(), ], $seeder ? ['--seeder' => $seeder] : ['--seed' => $this->shouldSeed()], $this->setMigrationPaths(), @@ -30,24 +38,4 @@ protected function migrateFreshUsing() return $results; } - - /** - * Determine if types should be dropped when refreshing the database. - * - * @return array|string> - */ - protected function setMigrationPaths() - { - $migrationSettings = []; - - if (property_exists($this, 'realPath')) { - $migrationSettings['--realpath'] = $this->realPath ?? false; - } - - if (property_exists($this, 'migrationPaths')) { - $migrationSettings['--path'] = $this->migrationPaths; - } - - return $migrationSettings; - } } diff --git a/src/Testing/DatabaseTruncation.php b/src/Testing/DatabaseTruncation.php index 7edf921..28270dd 100644 --- a/src/Testing/DatabaseTruncation.php +++ b/src/Testing/DatabaseTruncation.php @@ -5,14 +5,18 @@ namespace LaravelFreelancerNL\Aranguent\Testing; use Illuminate\Foundation\Testing\DatabaseTruncation as IlluminateDatabaseTruncation; +use LaravelFreelancerNL\Aranguent\Testing\Concerns\CanConfigureMigrationCommands; trait DatabaseTruncation { use IlluminateDatabaseTruncation; + use CanConfigureMigrationCommands; /** * The parameters that should be used when running "migrate:fresh". * + * Duplicate code because CanConfigureMigrationCommands has a conflict otherwise. + * * @return array */ protected function migrateFreshUsing() @@ -21,8 +25,11 @@ protected function migrateFreshUsing() $results = array_merge( [ + '--drop-analyzers' => $this->shouldDropAnalyzers(), + '--drop-graphs' => $this->shouldDropGraphs(), '--drop-views' => $this->shouldDropViews(), '--drop-types' => $this->shouldDropTypes(), + '--drop-all' => $this->shouldDropAll(), ], $seeder ? ['--seeder' => $seeder] : ['--seed' => $this->shouldSeed()], $this->setMigrationPaths(), @@ -30,24 +37,4 @@ protected function migrateFreshUsing() return $results; } - - /** - * Determine if types should be dropped when refreshing the database. - * - * @return array|string> - */ - protected function setMigrationPaths() - { - $migrationSettings = []; - - if (property_exists($this, 'realPath')) { - $migrationSettings['--realpath'] = $this->realPath ?? false; - } - - if (property_exists($this, 'migrationPaths')) { - $migrationSettings['--path'] = $this->migrationPaths; - } - - return $migrationSettings; - } } diff --git a/src/Testing/RefreshDatabase.php b/src/Testing/RefreshDatabase.php index 282a5dc..5d6e3fd 100644 --- a/src/Testing/RefreshDatabase.php +++ b/src/Testing/RefreshDatabase.php @@ -6,11 +6,13 @@ use Illuminate\Foundation\Testing\DatabaseTransactionsManager; use Illuminate\Foundation\Testing\RefreshDatabase as IlluminateRefreshDatabase; +use LaravelFreelancerNL\Aranguent\Testing\Concerns\CanConfigureMigrationCommands; use LaravelFreelancerNL\Aranguent\Testing\Concerns\PreparesTestingTransactions; trait RefreshDatabase { use PreparesTestingTransactions; + use CanConfigureMigrationCommands; use IlluminateRefreshDatabase; /** @@ -51,9 +53,12 @@ public function beginDatabaseTransaction() }); } + /** * The parameters that should be used when running "migrate:fresh". * + * Duplicate code because CanConfigureMigrationCommands has a conflict otherwise. + * * @return array */ protected function migrateFreshUsing() @@ -62,8 +67,11 @@ protected function migrateFreshUsing() $results = array_merge( [ + '--drop-analyzers' => $this->shouldDropAnalyzers(), + '--drop-graphs' => $this->shouldDropGraphs(), '--drop-views' => $this->shouldDropViews(), '--drop-types' => $this->shouldDropTypes(), + '--drop-all' => $this->shouldDropAll(), ], $seeder ? ['--seeder' => $seeder] : ['--seed' => $this->shouldSeed()], $this->setMigrationPaths(), diff --git a/tests/TestCase.php b/tests/TestCase.php index 208e1e3..a351dde 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -26,7 +26,7 @@ class TestCase extends \Orchestra\Testbench\TestCase protected ?ConnectionInterface $connection; - protected bool $dropViews = true; + protected bool $dropAll = true; protected bool $realPath = true; diff --git a/tests/Testing/DatabaseTruncationTest.php b/tests/Testing/DatabaseTruncationTest.php index ce60ac3..b508707 100644 --- a/tests/Testing/DatabaseTruncationTest.php +++ b/tests/Testing/DatabaseTruncationTest.php @@ -14,7 +14,6 @@ expect(count($tables))->toEqual($this->tableCount); }); - test('Ensure all characters are present', function () { $characters = Character::all();