I try to add this code in my DefaultControllerTest
$load = new Loader();
$load->load('src/AppBundle/DataFixtures/ORM/product.yml');
and here is the complete code of my controller
<?php
namespace Tests\AppBundle\Controller;
use Nelmio\Alice\Fixtures\Loader;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$load = new Loader();
$load->load('src/AppBundle/DataFixtures/ORM/product.yml');
$client = static::createClient();
$crawler = $client->request('GET', '/');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertContains('Welcome to Symfony', $crawler->filter('#container h1')->text());
}
}
If I run phpunit. It works and no errors found. It successfully tested but the problem here the product.yml doesn't insert any data in my database. But If I run this command bin/console hautelook_alice:doctrine:fixtures:load --append. This will works. It insert the data. How can I load the datafixture before I test the controller? I try to research more about it. but I have no clue on how to add it now.