Skip to content

Commit

Permalink
Fix test testLoadFixturesFilesWithPurgeModeTruncate
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre committed Apr 19, 2021
1 parent f04ac8e commit ec80721
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tests/Test/ConfigSqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,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 @@ -278,6 +278,8 @@ public function testLoadFixturesFiles(): void
$this->assertTrue(
$user->getEnabled()
);

return $fixtures;
}

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

$users = $this->userRepository->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 @@ -313,7 +327,16 @@ public function testLoadFixturesFilesWithPurgeModeTruncate(): void
$fixtures
);

$id = 1;
$users = $this->userRepository->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

0 comments on commit ec80721

Please sign in to comment.