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 80f51e5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/Test/ConfigMysqlCacheDbTest.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 Liip\Acme\Tests\App\Entity\User;
use Liip\Acme\Tests\AppConfigMysqlCacheDb\AppConfigMysqlKernelCacheDb;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
Expand Down Expand Up @@ -107,13 +108,16 @@ public function testLoadFixturesAndCheckBackup(): void

public function testLoadFixturesCheckReferences(): void
{
$this->markTestSkipped('This test is broken right now.');
$referenceRepository = $this->databaseTool->loadFixtures([
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData',
])->getReferenceRepository();

$this->assertCount(1, $referenceRepository->getReferences());

/** @var EntityManagerInterface $entityManager */
$entityManager = $this->getTestContainer()->get(EntityManagerInterface::class);
$entityManager->clear();

$referenceRepository = $this->databaseTool->loadFixtures([
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData',
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadSecondUserData',
Expand Down
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 80f51e5

Please sign in to comment.