-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(reset database): add dama decorator
- Loading branch information
Showing
14 changed files
with
180 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zenstruck\Foundry\ORM\ResetDatabase; | ||
|
||
use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Zenstruck\Foundry\Configuration; | ||
use Zenstruck\Foundry\Persistence\PersistenceManager; | ||
use Zenstruck\Foundry\Persistence\ResetDatabase\DatabaseResetterInterface; | ||
use Zenstruck\Foundry\Persistence\ResetDatabase\ResetDatabaseManager; | ||
|
||
/** | ||
* @internal | ||
* @author Nicolas PHILIPPE <nikophil@gmail.com> | ||
*/ | ||
final class DamaDatabaseResetter implements DatabaseResetterInterface | ||
{ | ||
public function __construct( | ||
private DatabaseResetterInterface $decorated, | ||
) { | ||
} | ||
|
||
public function resetDatabase(KernelInterface $kernel): void | ||
{ | ||
$isDAMADoctrineTestBundleEnabled = ResetDatabaseManager::isDAMADoctrineTestBundleEnabled(); | ||
|
||
if (!$isDAMADoctrineTestBundleEnabled) { | ||
$this->decorated->resetDatabase($kernel); | ||
|
||
return; | ||
} | ||
|
||
// disable static connections for this operation | ||
StaticDriver::setKeepStaticConnections(false); | ||
|
||
$this->decorated->resetDatabase($kernel); | ||
|
||
if (PersistenceManager::isOrmOnly()) { | ||
// add global stories so they are available after transaction rollback | ||
Configuration::instance()->stories->loadGlobalStories(); | ||
} | ||
|
||
// shutdown kernel before re-enabling static connections | ||
// this would prevent any error if some ResetInterface execute some queries (example: symfony/doctrine-messenger) | ||
$kernel->shutdown(); | ||
|
||
// re-enable static connections | ||
StaticDriver::setKeepStaticConnections(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zenstruck\Foundry\ORM\ResetDatabase; | ||
|
||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Zenstruck\Foundry\Persistence\ResetDatabase\ResetDatabaseManager; | ||
use Zenstruck\Foundry\Persistence\ResetDatabase\SchemaResetterInterface; | ||
|
||
/** | ||
* @internal | ||
* @author Nicolas PHILIPPE <nikophil@gmail.com> | ||
*/ | ||
final class DamaSchemaResetter implements SchemaResetterInterface | ||
{ | ||
public function __construct( | ||
private SchemaResetterInterface $decorated, | ||
) { | ||
} | ||
|
||
public function resetSchema(KernelInterface $kernel): void | ||
{ | ||
if (ResetDatabaseManager::isDAMADoctrineTestBundleEnabled()) { | ||
// not required as the DAMADoctrineTestBundle wraps each test in a transaction | ||
return; | ||
} | ||
|
||
$this->decorated->resetSchema($kernel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.