-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from alexislefebvre/feat-support-doctrine-orm-3
feat: support doctrine/orm 3
- Loading branch information
Showing
19 changed files
with
193 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,17 +25,18 @@ class LoadDependentUserData extends AbstractFixture implements DependentFixtureI | |
*/ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
/** @var User $user */ | ||
$user = clone $this->getReference('user'); | ||
|
||
$user = new User(); | ||
$user->setId(3); | ||
$user->setName('alice bar'); | ||
$user->setEmail('[email protected]'); | ||
|
||
$manager->persist($user); | ||
$manager->flush(); | ||
|
||
$user = clone $this->getReference('user'); | ||
|
||
$user = new User(); | ||
$user->setId(4); | ||
$user->setName('eve bar'); | ||
$user->setEmail('[email protected]'); | ||
|
||
$manager->persist($user); | ||
$manager->flush(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,18 +34,19 @@ public function __construct(DummyService $dummyService) | |
*/ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
/** @var User $user */ | ||
$user = clone $this->getReference('serviceUser'); | ||
|
||
$user = new User(); | ||
$user->setId(3); | ||
$user->setName('alice bar'); | ||
$user->setEmail('[email protected]'); | ||
$user->setDummyText($this->dummyService->getText()); | ||
|
||
$manager->persist($user); | ||
$manager->flush(); | ||
|
||
$user = clone $this->getReference('serviceUser'); | ||
|
||
$user = new User(); | ||
$user->setId(4); | ||
$user->setName('eve bar'); | ||
$user->setEmail('[email protected]'); | ||
|
||
$manager->persist($user); | ||
$manager->flush(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,9 @@ class LoadSecondUserData extends AbstractFixture | |
public function load(ObjectManager $manager): void | ||
{ | ||
$user = new User(); | ||
$user->setName('bar foo'); | ||
$user->setEmail('[email protected]'); | ||
$user->setId(3); | ||
$user->setName('alice bar'); | ||
$user->setEmail('[email protected]'); | ||
|
||
$manager->persist($user); | ||
$manager->flush(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,10 @@ public function load(ObjectManager $manager): void | |
|
||
$this->addReference('user', $user); | ||
|
||
$user = clone $this->getReference('user'); | ||
|
||
$user = new User(); | ||
$user->setId(2); | ||
$user->setName('bob bar'); | ||
$user->setEmail('[email protected]'); | ||
|
||
$manager->persist($user); | ||
$manager->flush(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,18 +36,18 @@ public function load(ObjectManager $manager): void | |
$manager->persist($user); | ||
$manager->flush(); | ||
|
||
$this->addReference('groupUser', $user); | ||
|
||
$user = clone $this->getReference('groupUser'); | ||
|
||
$user = new User(); | ||
$user->setId(2); | ||
$user->setName('bob bar'); | ||
$user->setEmail('[email protected]'); | ||
|
||
$manager->persist($user); | ||
$manager->flush(); | ||
|
||
$user = clone $this->getReference('groupUser'); | ||
|
||
$user = new User(); | ||
$user->setId(3); | ||
$user->setName('alice bar'); | ||
$user->setEmail('[email protected]'); | ||
|
||
$manager->persist($user); | ||
$manager->flush(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,11 +45,10 @@ public function load(ObjectManager $manager): void | |
$manager->persist($user); | ||
$manager->flush(); | ||
|
||
$this->addReference('serviceUser', $user); | ||
|
||
$user = clone $this->getReference('serviceUser'); | ||
|
||
$user = new User(); | ||
$user->setId(2); | ||
$user->setName('bob bar'); | ||
$user->setEmail('[email protected]'); | ||
|
||
$manager->persist($user); | ||
$manager->flush(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Liip\Acme\Tests\App\Entity\User: | ||
id{1..10}: | ||
user_id_{1..10}: | ||
id: <current()> | ||
name: <name()> | ||
email: <email()> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Liip\Acme\Tests\App\Entity\User: | ||
id{1..10}: | ||
custom_user_id_{11..20}: | ||
id: <current()> | ||
name: <foo('a string')> | ||
email: <email()> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,7 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence | |
* they are disabled by default (see phpunit.xml.dist). | ||
* | ||
* In order to run them, you have to set the MySQL connection | ||
* parameters in the Tests/AppConfigMysql/config.yml file and | ||
* add “--exclude-group ""” when running PHPUnit. | ||
* parameters in the Tests/AppConfigMysql/config.yml file. | ||
* | ||
* Use Tests/AppConfigMysql/AppConfigMysqlKernel.php instead of | ||
* Tests/App/AppKernel.php. | ||
|
@@ -95,7 +94,7 @@ public function testLoadEmptyFixtures(): void | |
/** | ||
* @group mysql | ||
*/ | ||
public function testLoadFixtures(int $firstUserId = 1): void | ||
public function testLoadFixtures(): void | ||
{ | ||
$fixtures = $this->databaseTool->loadFixtures([ | ||
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData', | ||
|
@@ -135,7 +134,7 @@ public function testLoadFixtures(int $firstUserId = 1): void | |
/** | ||
* @group mysql | ||
*/ | ||
public function testAppendFixtures(int $firstUserId = 1, int $thirdUserId = 3): void | ||
public function testAppendFixtures(): void | ||
{ | ||
$this->databaseTool->loadFixtures([ | ||
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData', | ||
|
@@ -169,17 +168,31 @@ public function testAppendFixtures(int $firstUserId = 1, int $thirdUserId = 3): | |
$user1->getEmail() | ||
); | ||
|
||
/** @var User $user */ | ||
/** @var User $user2 */ | ||
$user2 = $this->userRepository | ||
->findOneBy([ | ||
'email' => '[email protected]', | ||
]) | ||
; | ||
|
||
$this->assertNotNull($user2); | ||
|
||
$this->assertSame( | ||
'[email protected]', | ||
$user2->getEmail() | ||
); | ||
|
||
/** @var User $user3 */ | ||
$user3 = $this->userRepository | ||
->findOneBy([ | ||
'email' => 'bar@foo.com', | ||
'email' => 'alice@bar.com', | ||
]) | ||
; | ||
|
||
$this->assertNotNull($user3); | ||
|
||
$this->assertSame( | ||
'bar@foo.com', | ||
'alice@bar.com', | ||
$user3->getEmail() | ||
); | ||
} | ||
|
@@ -262,6 +275,8 @@ public function testLoadFixturesAndPurge(): void | |
$users | ||
); | ||
|
||
$this->getTestContainer()->get('doctrine')->getManager()->clear(); | ||
|
||
// Reload fixtures | ||
$this->databaseTool->loadFixtures([ | ||
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData', | ||
|
@@ -331,6 +346,29 @@ public function testLoadFixturesFiles(): void | |
$this->assertInstanceOf(User::class, $user); | ||
} | ||
|
||
/** | ||
* Load fixture which has a dependency. | ||
*/ | ||
public function testLoadDependentFixtures(): void | ||
{ | ||
$fixtures = $this->databaseTool->loadFixtures([ | ||
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadDependentUserData', | ||
]); | ||
|
||
$this->assertInstanceOf( | ||
'Doctrine\Common\DataFixtures\Executor\ORMExecutor', | ||
$fixtures | ||
); | ||
|
||
$users = $this->userRepository->findAll(); | ||
|
||
// The two files with fixtures have been loaded, there are 4 users. | ||
$this->assertCount( | ||
4, | ||
$users | ||
); | ||
} | ||
|
||
protected static function getKernelClass(): string | ||
{ | ||
return AppConfigMysqlKernel::class; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.