1

how I can get container to be able getting mys services in tests classes. I found the solution to require_once dir(__FILE__). '/...../AppKernel.php;, But when I go into WebTestCase class and found

protected static function createClient(array $options = array(), array $server = array())
{
    static::bootKernel($options);

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

    return $client;
}

Where Kernel booting, and another class KernelTestCase so I want to know I need to require_once AppKernel file or there is exist some more flexible and better method to get service container? Thanks!

2
  • @DOZ, no for now it extends from \PHPUnit_Framework_TestCase Commented Feb 3, 2015 at 11:16
  • you have to extend the WebTestCase so Commented Feb 3, 2015 at 11:17

1 Answer 1

6

Example :

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class Test extends WebTestCase
{
   public function testCreate()
   {
      $client = static::$kernel->getContainer()->get('yourservice')
   }
}
Sign up to request clarification or add additional context in comments.

1 Comment

actualy you forgot static::bootKernel(). :)

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.