From 83a0a8fad63afb54c271d49f379d358e0b7ab3b5 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Thu, 30 May 2019 22:50:07 +0200 Subject: [PATCH] Fix test testLoadFixturesFilesWithPurgeModeTruncate --- tests/Test/WebTestCaseTest.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/Test/WebTestCaseTest.php b/tests/Test/WebTestCaseTest.php index fc70a660..bdd6e02f 100644 --- a/tests/Test/WebTestCaseTest.php +++ b/tests/Test/WebTestCaseTest.php @@ -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', @@ -261,6 +261,8 @@ public function testLoadFixturesFiles(): void $this->assertTrue( $user->getEnabled() ); + + return $fixtures; } /** @@ -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); @@ -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());