Skip to content

Commit

Permalink
Fix test testLoadFixturesFilesWithPurgeModeTruncate
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre committed Jun 2, 2019
1 parent d04178c commit 83a0a8f
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tests/Test/WebTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function testLoadDependentFixturesWithDependencyInjected(): void
/**
* Use nelmio/alice.
*/
public function testLoadFixturesFiles(): void
public function testLoadFixturesFiles(): array
{
$fixtures = $this->loadFixtureFiles([
'@AcmeBundle/DataFixtures/ORM/user.yml',
Expand Down Expand Up @@ -261,6 +261,8 @@ public function testLoadFixturesFiles(): void
$this->assertTrue(
$user->getEnabled()
);

return $fixtures;
}

/**
Expand All @@ -282,6 +284,22 @@ public function testLoadNonexistentFixturesFiles(): void
*/
public function testLoadFixturesFilesWithPurgeModeTruncate(): void
{
// Load initial fixtures
$this->testLoadFixturesFiles();

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

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

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

// Load fixtures with append = true
$fixtures = $this->loadFixtureFiles([
'@AcmeBundle/DataFixtures/ORM/user.yml',
], true, null, 'doctrine', ORMPurger::PURGE_MODE_TRUNCATE);
Expand All @@ -297,7 +315,17 @@ public function testLoadFixturesFilesWithPurgeModeTruncate(): void
$fixtures
);

$id = 1;
$users = $em->getRepository('LiipAcme:User')
->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 \Liip\Acme\Tests\App\Entity\User $user */
foreach ($fixtures as $user) {
$this->assertSame($id++, $user->getId());
Expand Down

0 comments on commit 83a0a8f

Please sign in to comment.