6

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();

1 Answer 1

15

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()

Sign up to request clarification or add additional context in comments.

3 Comments

Still getting NULL. This is very strange.
@vinnylinux We should probably start a chat :)
I forgot to boot()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.