4
我想訪問Symfony2 WebTestCase中的容器,並且我得到NULL。有任何想法嗎?這裏是我的代碼:訪問Symfony2 WebTestCase中的容器,返回NULL
$this->client = static::createClient();
$container = $this->client->getContainer();
我想訪問Symfony2 WebTestCase中的容器,並且我得到NULL。有任何想法嗎?這裏是我的代碼:訪問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()
仍然得到NULL創建客戶。這很奇怪。 – vinnylinux 2012-07-30 18:56:24
@vinnylinux我們可能應該開始聊天:) – 2012-07-30 19:43:56
http://chat.stackoverflow.com/rooms/14648/symfony-tests – vinnylinux 2012-07-30 20:00:17