Skip to content

Commit

Permalink
fix: adapt 'globally disable persisstence' feature to split factories
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil committed Aug 11, 2023
1 parent f346521 commit b535afb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Test/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function _setUpFactories(): void
public static function _tearDownFactories(): void
{
try {
Factory::configuration()->enablePersist();
PersistentObjectFactory::persistenceManager()->enablePersist();
} catch (FoundryBootException) {
}

Expand All @@ -71,11 +71,11 @@ public static function _tearDownFactories(): void

public function disablePersist(): void
{
Factory::configuration()->disablePersist();
PersistentObjectFactory::persistenceManager()->disablePersist();
}

public function enablePersist(): void
{
Factory::configuration()->enablePersist();
PersistentObjectFactory::persistenceManager()->enablePersist();
}
}
6 changes: 5 additions & 1 deletion src/ZenstruckFoundryBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ final class ZenstruckFoundryBundle extends Bundle
{
public function boot(): void
{
if (!BaseFactory::isBooted() && $this->container) {
if (!$this->container) {
return;
}

if (!BaseFactory::isBooted()) {
BaseFactory::boot(
$this->container->get('.zenstruck_foundry.factory_manager'),
$this->container->get('.zenstruck_foundry.configuration')
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/ModelFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Foundry\BaseFactory;
use Zenstruck\Foundry\FactoryCollection;
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

Expand Down Expand Up @@ -492,7 +493,7 @@ public function cannot_access_repository_method_when_persist_disabled(): void
*/
public function assert_persist_is_re_enabled_automatically(): void
{
self::assertTrue(Factory::configuration()->isPersistEnabled());
self::assertTrue(PersistentObjectFactory::persistenceManager()->isPersistEnabled());

create($this->categoryClass(), ['name' => 'foo']);
$this->categoryFactoryClass()::assert()->count(1);
Expand Down

0 comments on commit b535afb

Please sign in to comment.