Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the container in Symfony2 WebTestCase, returns NULL

Tags:

php

symfony

I'm trying to access the container in a Symfony2 WebTestCase and i'm getting NULL. Any ideas? Here's my code:

$this->client = static::createClient();
$container = $this->client->getContainer();
like image 560
vinnylinux Avatar asked Jul 27 '12 21:07

vinnylinux


1 Answers

Assuming that you extend from WebTestCase class, you should call $this->createClient() instead of static method.

In case if you call this method as static, you should execute boot() method

    static::$kernel = static::createKernel($options);
    static::$kernel->boot();

    $client = static::$kernel->getContainer()->get('test.client');
    $client->setServerParameters($server);

Be sure to create client inside setUp()

like image 185
Vitalii Zurian Avatar answered Nov 14 '22 22:11

Vitalii Zurian