forked from liip/LiipFunctionalTestBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add append fixtures feature to loadFixtures method
- Loading branch information
Alfonso Machado
committed
Feb 5, 2018
1 parent
eca86d6
commit 3bca1f2
Showing
7 changed files
with
139 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Liip/FunctionalTestBundle | ||
* | ||
* (c) Lukas Kahwe Smith <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM; | ||
|
||
use Doctrine\Common\DataFixtures\AbstractFixture; | ||
use Doctrine\Common\DataFixtures\FixtureInterface; | ||
use Doctrine\Common\Persistence\ObjectManager; | ||
use Liip\FunctionalTestBundle\Tests\App\Entity\User; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
class LoadSecondUserData extends AbstractFixture implements FixtureInterface | ||
{ | ||
/** | ||
* @var ContainerInterface | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setContainer(ContainerInterface $container = null): void | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */ | ||
$user = new User(); | ||
$user->setName('bar foo'); | ||
$user->setEmail('[email protected]'); | ||
$user->setPassword('12341234'); | ||
$user->setAlgorithm('plaintext'); | ||
$user->setEnabled(true); | ||
$user->setConfirmationToken(null); | ||
|
||
$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 |
---|---|---|
|
@@ -118,6 +118,55 @@ public function testLoadFixtures(): void | |
); | ||
} | ||
|
||
/** | ||
* @group mysql | ||
*/ | ||
public function testAppendFixtures(): void | ||
{ | ||
$this->loadFixtures([ | ||
'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', | ||
]); | ||
|
||
$this->loadFixtures( | ||
['Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadSecondUserData'], | ||
true | ||
); | ||
|
||
// Load data from database | ||
$em = $this->getContainer() | ||
->get('doctrine.orm.entity_manager'); | ||
|
||
/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */ | ||
$user = $em->getRepository('LiipFunctionalTestBundle:User') | ||
->findOneBy([ | ||
'id' => 1, | ||
]); | ||
|
||
$this->assertSame( | ||
'[email protected]', | ||
$user->getEmail() | ||
); | ||
|
||
$this->assertTrue( | ||
$user->getEnabled() | ||
); | ||
|
||
/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */ | ||
$user = $em->getRepository('LiipFunctionalTestBundle:User') | ||
->findOneBy([ | ||
'id' => 3, | ||
]); | ||
|
||
$this->assertSame( | ||
'[email protected]', | ||
$user->getEmail() | ||
); | ||
|
||
$this->assertTrue( | ||
$user->getEnabled() | ||
); | ||
} | ||
|
||
/** | ||
* Data fixtures and purge. | ||
* | ||
|
@@ -148,7 +197,7 @@ public function testLoadFixturesAndExcludeFromPurge(): void | |
); | ||
|
||
$this->setExcludedDoctrineTables(['liip_user']); | ||
$this->loadFixtures([], null, 'doctrine', 2); | ||
$this->loadFixtures([], false, null, 'doctrine', 2); | ||
|
||
// The exclusion from purge worked, the user table is still alive and well. | ||
$this->assertSame( | ||
|
@@ -188,7 +237,7 @@ public function testLoadFixturesAndPurge(): void | |
); | ||
|
||
// 1 → ORMPurger::PURGE_MODE_DELETE | ||
$this->loadFixtures([], null, 'doctrine', 1); | ||
$this->loadFixtures([], false, null, 'doctrine', 1); | ||
|
||
// The purge worked: there is no user. | ||
$this->assertSame( | ||
|
@@ -210,7 +259,7 @@ public function testLoadFixturesAndPurge(): void | |
); | ||
|
||
// 2 → ORMPurger::PURGE_MODE_TRUNCATE | ||
$this->loadFixtures([], null, 'doctrine', 2); | ||
$this->loadFixtures([], false, null, 'doctrine', 2); | ||
|
||
// The purge worked: there is no user. | ||
$this->assertSame( | ||
|
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