Created
April 24, 2012 13:41
-
-
Save lytithwyn/2479753 to your computer and use it in GitHub Desktop.
Fixtures inside functional tests blog post
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
<?php | |
# make sure there were no problems loading the fixtures | |
self::assertNotContains('Exception', $cliCapturedOutput); | |
?> |
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
<?php | |
# create a cli application | |
$application = new Application($client->getKernel()); | |
$application->setAutoExit(false); | |
?> |
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
<?php | |
# get the container | |
$client = static::createClient(); | |
self::$container = $client->getContainer(); | |
$doctrine = self::$container->get('doctrine'); | |
$em = $doctrine->getEntityManager(); | |
?> |
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
<?php | |
namespace TestFrameWork; | |
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | |
use Doctrine\ORM\Tools\SchemaTool; | |
use Symfony\Component\Console\Input\StringInput; | |
use Symfony\Component\Console\Output\StreamOutput; | |
use Symfony\Bundle\FrameworkBundle\Console\Application; | |
class FreshFixtureWebTestCase extends WebTestCase { | |
protected static $container; | |
protected static $schemaTool; | |
public static function setUpBeforeClass() { | |
# get the container | |
$client = static::createClient(); | |
self::$container = $client->getContainer(); | |
$doctrine = self::$container->get('doctrine'); | |
$em = $doctrine->getEntityManager(); | |
# get the list of all our classes' metadata | |
$mdf = $em->getMetadataFactory(); | |
$classes = $mdf->getAllMetadata(); | |
# drop the schema and create a fresh one using our metadata | |
self::$schemaTool = new SchemaTool($em); | |
self::$schemaTool->dropDatabase(); | |
self::$schemaTool->createSchema($classes); | |
# create a cli application | |
$application = new Application($client->getKernel()); | |
$application->setAutoExit(false); | |
# use the cli to load the fixtures | |
$cliOutputFP = tmpfile(); | |
$cliOutput = new StreamOutput($cliOutputFP); | |
$cliInput = new StringInput('doctrine:fixtures:load'); | |
$application->run($cliInput, $cliOutput); | |
# collect the output from the load fixtures command | |
fseek($cliOutputFP, 0); | |
$cliCapturedOutput = ''; | |
while(!feof($cliOutputFP)) { | |
$cliCapturedOutput = fread($cliOutputFP, 4096); | |
} | |
fclose($cliOutputFP); | |
# make sure there were no problems loading the fixtures | |
self::assertNotContains('Exception', $cliCapturedOutput); | |
} | |
public static function tearDownAfterClass() { | |
# clear all our changes | |
self::$schemaTool->dropDatabase(); | |
} | |
} | |
?> |
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
<?php | |
namespace TestFrameWork; | |
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | |
class FreshFixtureWebTestCase extends WebTestCase { | |
public static function setUpBeforeClass() { | |
} | |
public static function tearDownAfterClass() { | |
} | |
} | |
?> |
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
<?php | |
# get the list of all our classes' metadata | |
$mdf = $em->getMetadataFactory(); | |
$classes = $mdf->getAllMetadata(); | |
?> |
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
<?php | |
# use the cli to load the fixtures | |
$cliOutputFP = tmpfile(); | |
$cliOutput = new StreamOutput($cliOutputFP); | |
$cliInput = new StringInput('doctrine:fixtures:load'); | |
$application->run($cliInput, $cliOutput); | |
# collect the output from the load fixtures command | |
fseek($cliOutputFP, 0); | |
$cliCapturedOutput = ''; | |
while(!feof($cliOutputFP)) { | |
$cliCapturedOutput = fread($cliOutputFP, 4096); | |
} | |
fclose($cliOutputFP); | |
?> |
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
<?php | |
# drop the schema and create a fresh one using our metadata | |
self::$schemaTool = new SchemaTool($em); | |
self::$schemaTool->dropDatabase(); | |
self::$schemaTool->createSchema($classes); | |
?> |
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
<?php | |
public static function tearDownAfterClass() { | |
# clear all our changes | |
self::$schemaTool->dropDatabase(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment