我无法运行功能测试,但仍然可以获得信息:
/ blog公共URL正确加载。 断言500等于200失败。
正如我用debug $ client-> request('GET',$ url)检查的那样,创建地址http://localhost/blog是错误的页面地址。正确的页面地址为http://project.local/blog或http://localhost/project/public/blog
class PagesControllerTest extends WebTestCase
{
public function testShowPost()
{
$client = static::createClient();
$client->request('GET', '/blog');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
phpunit.xml.dist
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="App\Kernel" />
<server name="HOSTNAME" value="http://project.local" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="/foobar/" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
<listener class="\DAMA\DoctrineTestBundle\PHPUnit\PHPUnitListener" />
</listeners>
</phpunit>
答案 0 :(得分:0)
您可以创建.env.test,此文件将在.env文件之后加载,并覆盖测试环境的环境变量。
DATABASE_URL=sqlite:///%kernel.project_dir%/data/database_test.sqlite