Skip to content

Commit 7894633

Browse files
committed
fix: cache reference repository
1 parent 2b810cd commit 7894633

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/Services/DatabaseTools/ORMDatabaseTool.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,42 @@
2727
use Liip\TestFixturesBundle\Event\PreFixtureBackupRestoreEvent;
2828
use Liip\TestFixturesBundle\Event\ReferenceSaveEvent;
2929
use Liip\TestFixturesBundle\LiipTestFixturesEvents;
30+
use Symfony\Contracts\Service\ResetInterface;
3031

3132
/**
3233
* @author Aleksey Tupichenkov <alekseytupichenkov@gmail.com>
3334
*/
34-
class ORMDatabaseTool extends AbstractDbalDatabaseTool
35+
class ORMDatabaseTool extends AbstractDbalDatabaseTool implements ResetInterface
3536
{
3637
/**
3738
* @var EntityManager
3839
*/
3940
protected $om;
4041

42+
private ?ProxyReferenceRepository $referenceRepository = null;
43+
4144
/**
4245
* @var bool
4346
*/
4447
private $shouldEnableForeignKeyChecks = false;
4548

49+
public function reset()
50+
{
51+
$this->referenceRepository = null;
52+
}
53+
4654
public function getType(): string
4755
{
4856
return 'ORM';
4957
}
5058

5159
public function loadFixtures(array $classNames = [], bool $append = false): AbstractExecutor
5260
{
53-
$referenceRepository = new ProxyReferenceRepository($this->om);
61+
if (null === $this->referenceRepository || false === $append) {
62+
$this->referenceRepository = new ProxyReferenceRepository($this->om);
63+
}
64+
65+
$referenceRepository = $this->referenceRepository;
5466

5567
/** @var Configuration $config */
5668
$config = $this->om->getConfiguration();

tests/AppConfigSqliteUrl/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
doctrine:
44
dbal:
5-
url: 'sqlite:///%kernel.project_dir%/var/app.db'
5+
url: 'sqlite:///%kernel.cache_dir%/test.db'
66

tests/Test/ConfigMysqlCacheDbTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public function testLoadFixturesAndCheckBackup(): void
118118
*/
119119
public function testLoadFixturesCheckReferences(): void
120120
{
121-
$this->markTestSkipped('This test is broken right now.');
122121
$referenceRepository = $this->databaseTool->loadFixtures([
123122
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData',
124123
])->getReferenceRepository();

tests/Test/ConfigMysqlTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@ public function testAppendFixtures(): void
140140
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData',
141141
]);
142142

143-
$this->databaseTool->loadFixtures(
143+
$referenceRepository = $this->databaseTool->loadFixtures(
144144
['Liip\Acme\Tests\App\DataFixtures\ORM\LoadSecondUserData'],
145145
true
146-
);
146+
)->getReferenceRepository();
147+
148+
$this->assertCount(2, $referenceRepository->getReferences());
147149

148150
// Load data from database
149151
$users = $this->userRepository->findAll();

0 commit comments

Comments
 (0)