我正在尝试访问 Symfony2 WebTestCase 中的容器,但我得到的是 NULL。有任何想法吗?这是我的代码:
$this->client = static::createClient();
$container = $this->client->getContainer();
最佳答案
假设您从 WebTestCase
类扩展,您应该调用 $this->createClient()
而不是静态方法。
如果您将此方法作为静态方法调用,则应执行boot()
方法
static::$kernel = static::createKernel($options);
static::$kernel->boot();
$client = static::$kernel->getContainer()->get('test.client');
$client->setServerParameters($server);
一定要在setUp()
关于php - 访问 Symfony2 WebTestCase 中的容器,返回 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11695872/