问题
I've got an error when i try to launch my functional tests.
"The BrowserKit component is not available."
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.
As you can see my unit tests are ok. But not my functionals and when I check my composer.json I can see it.
"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.*"
},
And it's present in my /vendor folder.
And there is my 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>
For finish this is my test
<?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());
}
}
Have you got any ideas ?
Thank you for helping.
回答1:
Founded ! I think it was a problem with my composer.json
I uninstall both test-pack en phpunit-bridge and reinstall only test-pack.
composer remove --dev test-pack symfony/phpunit-bridge
composer require --dev test-pack
来源:https://stackoverflow.com/questions/54828903/the-browserkit-component-is-not-available