Skip to content

Commit

Permalink
fix: clear entity manager to avoid conflicts
Browse files Browse the repository at this point in the history
when loading fixtures
  • Loading branch information
alexislefebvre committed Jul 2, 2024
1 parent ebe5cce commit cf1244f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/Test/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Liip\Acme\Tests\Test;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectRepository;
use Liip\Acme\Tests\App\Entity\User;
use Liip\Acme\Tests\AppConfig\AppConfigKernel;
Expand Down Expand Up @@ -44,6 +45,7 @@ class ConfigTest extends KernelTestCase
private $userRepository;
/** @var SqliteDatabaseBackup */
private $sqliteDatabaseBackup;
private EntityManagerInterface $entityManager;

protected function setUp(): void
{
Expand All @@ -62,6 +64,10 @@ protected function setUp(): void
$this->sqliteDatabaseBackup = $this->getTestContainer()->get(SqliteDatabaseBackup::class);

$this->assertInstanceOf(SqliteDatabaseBackup::class, $this->sqliteDatabaseBackup);

$this->entityManager = $this->getTestContainer()->get(EntityManagerInterface::class);

$this->assertInstanceOf(EntityManagerInterface::class, $this->entityManager);
}

/**
Expand Down Expand Up @@ -135,6 +141,8 @@ public function testCacheCanBeDisabled(): void

sleep(2);

$this->clearEntityManager();

// Reload the fixtures.
$this->databaseTool->loadFixtures($fixtures);

Expand Down Expand Up @@ -183,6 +191,8 @@ public function testBackupIsRefreshed(): void

sleep(2);

$this->clearEntityManager();

// Reload the fixtures.
$this->databaseTool->loadFixtures($fixtures);

Expand All @@ -207,6 +217,8 @@ public function testBackupIsRefreshed(): void

sleep(2);

$this->clearEntityManager();

// Update the filemtime of the fixture file used as a dependency.
touch($dependentFixtureFilePath);

Expand Down Expand Up @@ -237,6 +249,11 @@ protected static function getKernelClass(): string
return AppConfigKernel::class;
}

protected function clearEntityManager(): void
{
$this->entityManager->clear();
}

protected function tearDown(): void
{
parent::tearDown();
Expand Down

0 comments on commit cf1244f

Please sign in to comment.