1

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 ?

Community
  • 1
  • 1
mika
  • 1,971
  • 3
  • 18
  • 32
  • `LiipFunctionalTestBundle` expects `setup()` to include an array `$classes = array(...)` of fixtures and then `$this->loadFixtures($classes);` Your setup shows no classes and `loadFixtures()` is devoid of any class array. – geoB May 15 '15 at 14:47
  • @geoB the error message suggests this is not the issue. I updated the post though, to avoid confusion. Thanks for the correction. – mika May 15 '15 at 14:54
  • @dragoste I do not see any mention of the loadFixtures function in this post. Furthermore, it is 2 years old, and it seems these bundles have been quite updated since. I do believe there is a much better way to do this today. – mika May 15 '15 at 14:59
  • @mika sorry, didn't read your question carefully. 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. – Jakub Matczak May 15 '15 at 15:06
  • @dragoste Oh yes... I was myself going through the Liip installation instructions too fast: I was using Symfony\Bundle\FrameworkBundle\Test\WebTestCase; which does not have the loadFixtures function. If you make your comment an answer, that will be the correct one. Many thanks ! – mika May 15 '15 at 15:29

1 Answers1

2

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.

Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64