BrowserKit组件不可用

问题描述 投票:0回答:1

我有一个扩展WebTestCase的测试。它还没有做太多的事情:

namespace Tests\Application\EndToEnd;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class AuthenticationTest extends WebTestCase

    {
        public function testAuthenticationMethodNotAllowed()
        {   
            $client = static::createClient();
            self::assertTrue(true);
        }
    }

但是,即使这一点也足以在我运行测试时触发错误:

有1个错误:

1)Tests \ Application \ EndToEnd \ AuthenticationTest :: testAuthenticationMethodNotAllowed LogicException:如果BrowserKit组件不可用,则无法创建功能测试中使用的客户端。尝试运行“composer require symfony / browser-kit”。

运行composer require symfony/browser-kitcomposer require --dev symfony/browser-kit并不能解决问题。

我也尝试了提到here的修复,没有任何改进。

这是一个已知的问题?我还应该尝试其他方法吗?

===

更新:这是我的test.xml文件中的内容:

<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <parameters>
        <parameter key="test.client.parameters" type="collection"></parameter>
    </parameters>

    <services>
        <defaults public="false" />

        <service id="test.client" class="Symfony\Bundle\FrameworkBundle\Client" shared="false" public="true">
            <argument type="service" id="kernel" />
            <argument>%test.client.parameters%</argument>
            <argument type="service" id="test.client.history" />
            <argument type="service" id="test.client.cookiejar" />
        </service>

        <service id="test.client.history" class="Symfony\Component\BrowserKit\History" shared="false" />

        <service id="test.client.cookiejar" class="Symfony\Component\BrowserKit\CookieJar" shared="false" />

        <service id="test.session.listener" class="Symfony\Component\HttpKernel\EventListener\TestSessionListener">
            <tag name="kernel.event_subscriber" />
            <argument type="service_locator">
                <argument key="session" type="service" id="session" on-invalid="ignore" />
            </argument>
        </service>

        <service id="test.service_container" class="Symfony\Bundle\FrameworkBundle\Test\TestContainer" public="true">
            <argument type="service" id="kernel" />
            <argument>test.private_services_locator</argument>
        </service>

        <service id="test.private_services_locator" class="Symfony\Component\DependencyInjection\ServiceLocator" public="true">
            <argument type="collection" />
        </service>
    </services>
</container>
php symfony testing composer-php
1个回答
1
投票

此错误消息不仅在未安装BrowserKit组件时触发,而且在framework.test配置选项不是true时触发(因为在这种情况下,test.client服务将永远不会注册)。

您需要确保启用此选项,并且您的测试实际上是在test环境中执行的。

© www.soinside.com 2019 - 2024. All rights reserved.