我找到了这篇文章,因为我自己在测试中需要配置参数。这是谷歌的第一次成功。
但是,这是一个可行的解决方案。可能有更好的。
<?php
...
require_once(__DIR__ . "/../../../../../app/AppKernel.php");
class MediaImageTest extends WebTestCase
{
private $_application;
private $storagePath;
public function setUp() {
$kernel = new \AppKernel('test', true);
$kernel->boot();
$this->_application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$this->_application->setAutoExit(false)
$this->storagePath = $this->_application->getKernel()->getContainer()->getParameter('media_path');
}
...
}
你也可以看看这个:Access Symfony 2 container via Unit test?
是在单元测试中访问内核的更清洁的解决方案。