Reputation: 1160
I have a test that extends WebTestCase. It doesn't do much yet:
namespace Tests\Application\EndToEnd;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AuthenticationTest extends WebTestCase
{
public function testAuthenticationMethodNotAllowed()
{
$client = static::createClient();
self::assertTrue(true);
}
}
But even this little bit is enough to trigger an error when I run the test:
There was 1 error:
1) Tests\Application\EndToEnd\AuthenticationTest::testAuthenticationMethodNotAllowed LogicException: You cannot create the client used in functional tests if the BrowserKit component is not available. Try running "composer require symfony/browser-kit".
Running composer require symfony/browser-kit
and also composer require --dev symfony/browser-kit
does not fix the problem.
I also tried the fix mentioned here, with no improvement.
Is this a known issue? Are there other approaches I should try?
===
Update: Here is the content in my test.xml
file:
<?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>
Upvotes: 4
Views: 5234
Reputation: 5881
This error message is not only triggered when the BrowserKit component is not installed, but also when the framework.test
config option is not true
(as in this case the test.client
service will never be registered).
You need to make sure that this option is enabled and that your test is actually executed in the test
environment.
Upvotes: 3