BrowserKit组件不可用

时间:2019-02-22 14:09:47

标签: phpunit symfony4 functional-testing

尝试启动功能测试时出现错误。
“ BrowserKit组件不可用。”

void pushMagnet(final String apiKey, final String magnetLink, final Context context) {
    final String url = "https://premiumize.me/api/transfer/create?apikey=" + apiKey;

    Map<String, String> magnetSrc = new HashMap<>();
    //Parameters i want to send
    magnetSrc.put("src", magnetLink);

    RequestQueue queue = Volley.newRequestQueue(context);

    JsonObjectRequest stringRequest = new JsonObjectRequest(Request.Method.POST, url,
            //here added as an JSON Object
            new JSONObject(magnetSrc),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.e("Rest Response:", response.toString());
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("Rest Error:", error.toString());
        }
    }
    ) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> headers = new HashMap<>();
            headers.put("accept", "application/json");
            headers.put("Content-Type", "multipart/form-data");

            return headers;
        }
    };
    queue.add(stringRequest);
}

您可以看到我的单元测试还可以。 但是没有我的功能,当我检查composer.json时,我可以看到它。

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.

它存在于我的/ vendor文件夹中。

还有我的phpunit.xml.dist

"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.*"
},

最后,这是我的考验

<?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>

您有什么想法吗?
谢谢您的帮助。

2 个答案:

答案 0 :(得分:1)

成立! 我认为我的composer.json有问题

我同时卸载了phpunit-bridge和test-pack并仅重新安装了test-pack。

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

答案 1 :(得分:0)

如错误所写,您必须安装BrowserKit组件:

composer require --dev symfony/browser-kit

如果您不仅在测试期间需要BrowserKit,请删除--dev