1

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

Community
  • 1
  • 1
Adib Aroui
  • 4,981
  • 5
  • 42
  • 94
  • 1
    https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/TestCase.php#L2210 Went through all the classes. This is where method is originated from. – E_p Jul 14 '16 at 21:58
  • @E_p, thank you very much I understand now. – Adib Aroui Jul 14 '16 at 22:06

1 Answers1

2

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

Kal Zekdor
  • 1,172
  • 2
  • 13
  • 23
  • 1
    Furthermore, when you extend a class, you aren't limited to redefining existing methods. You can add entirely new methods, which can then be called by consuming code down the road. – Kal Zekdor Jul 14 '16 at 22:05
  • Thank you for your informative feedback. I totally understand now. I forgot that PHPUnit comes as intgrated part of the Symfony2 standard edition. I thought it comes with the liipfunctionaltestbundle. Stupid mistake. – Adib Aroui Jul 14 '16 at 22:09