Search code examples
symfonydoctrine-ormfunctional-testingfixtures

Loading Fixtures for functional tests in Symfony 2: Call to undefined method MyControllerTest::loadFixtures())


I am trying to find the easy way to load my fixtures in Symfony 2.6 to run functional tests. This is a quite common question, and has been asked a few times, but the answers I have found so far do not quite reach my expectations:

  • Some rely on running the command line from inside the functional test.
  • Other run manually each one of the defined fixtures, and then take care of creating and deleting the database.

There is a lot of overhead in both cases (use statements and manual code), for a task that I believe is very standard.

On the other hand, these same posts recommend the LiipFunctionalTestBundle. Going for it, here is what I read in the installation instructions:

write fixture classes and call loadFixtures() method from the bundled Test\WebTestCase class. Please note that loadFixtures() will delete the contents from the database before loading the fixtures."

So I tried...

namespace AppBundle\Test\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class MyControllerTest extends WebTestCase
{
    public function setUp()
    {
        $classes = array(
                'AppBundle\DataFixtures\LoadUserData',
        );
        $this->loadFixtures($classes);
    }
    ...
}

With no luck:

Call to undefined method AppBundle\Tests\Controller\MyControllerTest::loadFixtures() in /gitrepos/myproject/src/AppBundle/Tests/Controller/MyControllerTest.php on line 15

a static call gives the same error...

self:loadFixtures($classes);

I really think I am missing something pretty obvious. Anyone can get me back on track ?


Solution

  • I can see you're using

    Oro\Bundle\TestFrameworkBundle\Test\WebTestCase
    

    as the base class while I think you should use

    Liip\FunctionalTestBundle\Test\WebTestCase
    

    to be able to call this method.