Skip to content

Commit

Permalink
feat: skip resetDatabase when migrations are up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
haase-fabian committed Jan 31, 2024
1 parent 49341f3 commit 7d5ad3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Test/DatabaseResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public static function hasBeenReset(): bool
return self::$hasBeenReset;
}

public static function isDAMADoctrineTestBundleAvailable(): bool
{
return \class_exists(StaticDriver::class);
}

public static function isDAMADoctrineTestBundleEnabled(): bool
{
return \class_exists(StaticDriver::class) && StaticDriver::isKeepStaticConnections();
Expand Down
9 changes: 9 additions & 0 deletions src/Test/ORMDatabaseResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public function __construct(private Application $application, private ManagerReg

public function resetDatabase(): void
{
if (DatabaseResetter::isDAMADoctrineTestBundleAvailable() && $this->isResetUsingMigrations()) {
try{
$this->runCommand($this->application, 'doctrine:migrations:up-to-date', ['--fail-on-unregistered' => true]);
// not required as the database schema is already up-to-date
return;
}catch(\RuntimeException $e){
}
}

$this->dropAndResetDatabase();
$this->createSchema();
}
Expand Down

0 comments on commit 7d5ad3b

Please sign in to comment.