Created
June 4, 2013 12:55
-
-
Save kix/5705677 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
/** | |
* WebTestCase client-aware test case | |
*/ | |
trait ClientAware | |
{ | |
/** | |
* @var \Symfony\Bundle\FrameworkBundle\Client | |
*/ | |
private $client; | |
/** | |
* Sets up client | |
*/ | |
public function setUp() | |
{ | |
$this->client = static::createClient(); | |
} | |
/** | |
* @return \Symfony\Component\DependencyInjection\ContainerInterface | |
*/ | |
public function getContainer() | |
{ | |
return $this->client->getContainer(); | |
} | |
} |
This file contains hidden or 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
<?php | |
use \Doctrine\Common\DataFixtures; | |
/** | |
* Purges DB, needs container | |
*/ | |
trait PurgeDb | |
{ | |
use ClientAware { | |
setUp as clientAwareSetUp; | |
} | |
/** | |
* Calls ClientAware trait method | |
*/ | |
public function setUp() | |
{ | |
$this->clientAwareSetUp(); | |
$em = $this->getContainer()->get('doctrine.orm.entity_manager'); | |
$purger = new DataFixtures\Purger\ORMPurger($em); | |
$purger->purge(); | |
} | |
} |
This file contains hidden or 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
<?php | |
use \Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | |
use PurgeDb; | |
class FakerTest extends WebTestCase | |
{ | |
use PurgeDb; | |
public function testPurgeAndPopulateEntity() | |
{ | |
/** @var $em \Doctrine\ORM\EntityManager */ | |
$em = $this->getContainer()->get('doctrine.orm.entity_manager'); | |
$this->assertEquals( | |
0, | |
count($em->getRepository('WtProMainBundle:User')->findAll()) | |
); | |
$faker = new \My\Faker($this->getContainer()); | |
$populator = $faker->getPopulator(); | |
$populator->addEntity('Entity\User', 3); | |
$populator->execute( | |
$this->getContainer()->get('doctrine.orm.entity_manager') | |
); | |
$this->assertEquals( | |
3, | |
count($em->getRepository('WtProMainBundle:User')->findAll()) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment