我尝试将此代码添加到我的 DefaultControllerTest
$load = new Loader();
$load->load('src/AppBundle/DataFixtures/ORM/product.yml');
这是我的控制器的完整代码
<?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());
}
}
如果我运行 phpunit。它可以工作并且没有发现错误。它已成功测试,但这里的问题 product.yml 没有在我的数据库中插入任何数据。但是如果我运行这个命令 bin/console hautelook_alice:doctrine:fixtures:load --append。这将起作用。它插入数据。在测试控制器之前如何加载数据夹具?我尝试对此进行更多研究。但我现在不知道如何添加它。