Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
executionOrder="random"
>

<php>
Expand Down
3 changes: 2 additions & 1 deletion src/Services/DatabaseTools/ORMDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ protected function cleanDatabase(): void

protected function disableForeignKeyChecksIfApplicable(): void
{
if (!$this->isMysql()) {
// Don't disable FOREIGN_KEY_CHECKS is the database is not created yet
if (!$this->isMysql() || !$this->connection->isConnected()) {
return;
}

Expand Down
33 changes: 31 additions & 2 deletions tests/Test/ConfigSqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public function testLoadDependentFixturesWithDependencyInjected(): void
/**
* Use nelmio/alice.
*/
public function testLoadFixturesFiles(): void
public function testLoadFixturesFiles(): array
{
$fixtures = $this->databaseTool->loadAliceFixture([
'@AcmeBundle/DataFixtures/ORM/user.yml',
Expand Down Expand Up @@ -362,6 +362,8 @@ public function testLoadFixturesFiles(): void
;

$this->assertIsString($user->getName());

return $fixtures;
}

/**
Expand All @@ -383,8 +385,24 @@ public function testLoadNonexistentFixturesFiles(): void
*/
public function testLoadFixturesFilesWithPurgeModeTruncate(): void
{
// Load initial fixtures
$this->testLoadFixturesFiles();

$em = $this->getContainer()
->get('doctrine.orm.entity_manager');

$users = $em->getRepository(User::class)
->findAll();

// There are 10 users in the database
$this->assertSame(
10,
count($users)
);

$this->databaseTool->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);

// Load fixtures with append = true
$fixtures = $this->databaseTool->loadAliceFixture([
'@AcmeBundle/DataFixtures/ORM/user.yml',
], true);
Expand All @@ -397,7 +415,18 @@ public function testLoadFixturesFilesWithPurgeModeTruncate(): void
$fixtures
);

$id = 1;
$users = $em->getRepository(User::class)
->findAll();

// There are only 10 users in the database
$this->assertSame(
10,
count($users)
);

// Auto-increment hasn't been altered, so ids start from 11
$id = 11;

/** @var User $user */
foreach ($fixtures as $user) {
$this->assertSame($id++, $user->getId());
Expand Down
Loading