我尝试启动功能测试时遇到错误。 “BrowserKit组件不可用。”
php ./bin/phpunit
#!/usr/bin/env php
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
Testing Project Test Suite
E.. 3 / 3 (100%)
Time: 367 ms, Memory: 16.00MB
There was 1 error:
1) App\Tests\Controller\DefaultControllerTest::testLoginPage
LogicException: You cannot create the client used in functional tests if the BrowserKit component is not available. Try running "composer require symfony/browser-kit".
xxx\vendor\symfony\framework-bundle\Test\WebTestCase.php:39
xxx\tests\Controller\DefaultControllerTest.php:13
ERRORS!
Tests: 3, Assertions: 6, Errors: 1.
如你所见,我的单元测试还可以。但不是我的功能,当我检查我的composer.json时,我可以看到它。
"require-dev": {
"symfony/browser-kit": "4.2.*",
"symfony/css-selector": "4.2.*",
"symfony/debug-pack": "*",
"symfony/phpunit-bridge": "4.2.*",
"symfony/profiler-pack": "*",
"symfony/test-pack": "^1.0",
"symfony/web-server-bundle": "4.2.*"
},
它出现在我的/ vendor文件夹中。
还有我的phpunit.xml.dist
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupStaticAttributes="false"
bootstrap="config/bootstrap.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
strict="false"
verbose="false"
>
<php>
<!-- The application kernel -->
<env name="KERNEL_CLASS" value="App\Kernel" />
<!-- ###+ symfony/framework-bundle ### -->
<env name="APP_ENV" value="dev"/>
<env name="APP_SECRET" value="xxxx"/>
<!-- ###- symfony/framework-bundle ### -->
<!-- ###+ nelmio/cors-bundle ### -->
<env name="CORS_ALLOW_ORIGIN" value="^https?://localhost(:[0-9]+)?$"/>
<!-- ###- nelmio/cors-bundle ### -->
</php>
<loggin>
<log type="coverage-html" target="./build/coverage" lowUpperBound="35"
highLowerBound="70"/>/>
</loggin>
<testsuites>
<testsuite name="Project Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
完成这是我的测试
<?php
namespace App\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
private $client = null;
public function setUp()
{
$this->client = static::createClient();
}
public function testLoginPage()
{
$url = $this->router->generate('index');
$crawler = $this->client->request('GET', $url);
$this->assertSame(200, $client->getResponse()->getStatusCode());
//$this->assertContains('Login', $crawler->filter('h1')->text());
}
}
你有什么想法吗? 谢谢你的帮忙。
成立了!我认为这是我的composer.json的一个问题
我卸载了test-pack和phpunit-bridge,只重新安装了test-pack。
composer remove --dev test-pack symfony/phpunit-bridge
composer require --dev test-pack