whiteletters in blankpapers whiteletters in blankpapers - 4 months ago 9
PHP Question

Why this method get executed without being called?

According to this documentation, I can write a

setUp()
function in my test class, like:

use Doctrine\ORM\Tools\SchemaTool;
use Liip\FunctionalTestBundle\Test\WebTestCase;

class AccountControllerTest extends WebTestCase
{
public function setUp()
{
$em = $this->getContainer()->get('doctrine')->getManager();
if (!isset($metadatas)) {
$metadatas = $em->getMetadataFactory()->getAllMetadata();
}
$schemaTool = new SchemaTool($em);
$schemaTool->dropDatabase();
if (!empty($metadatas)) {
$schemaTool->createSchema($metadatas);
}
$this->postFixtureSetup();

$fixtures = array(
'Acme\MyBundle\DataFixtures\ORM\LoadUserData',
);
$this->loadFixtures($fixtures);
}
//...
}


But when I look for the
setUp()
method in the extended WebTestCase class, I don't find it. My understanding is that I can redefine a method from parent class in the child class. Parent class is:

https://github.com/liip/LiipFunctionalTestBundle/blob/master/Test/WebTestCase.php

Please to explain to me why and when this method get executed? Thank you

Answer

setUp() is actually used by PHPUnit, which the Symfony testing framework extends.

Take a look at the PHPUnit documentation for more info: https://phpunit.de/manual/current/en/fixtures.html

Here's a link to the actual abstract class that Symfony is extending: https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/TestCase.php#L2210

Comments