BrowserKit 组件不可用

吉姆

当我尝试启动我的功能测试时出现错误。
“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 en phpunit-bridge 并只重新安装了 test-pack。

composer remove --dev test-pack symfony/phpunit-bridge
composer require --dev test-pack

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章