在功能测试中使用globals(使用Symfony和Codeception)
我想测试这个函数:在功能测试中使用globals(使用Symfony和Codeception),symfony,kernel,functional-testing,codeception,Symfony,Kernel,Functional Testing,Codeception,我想测试这个函数: static protected function getContainerInterface() { global $kernel; if (get_class($kernel) == 'AppCache') { /** @var \AppCache $cache */ $cache = $kernel; $kernel = $cache->getKernel(); } return $k
static protected function getContainerInterface()
{
global $kernel;
if (get_class($kernel) == 'AppCache') {
/** @var \AppCache $cache */
$cache = $kernel;
$kernel = $cache->getKernel();
}
return $kernel->getContainer();
}
并得到一个错误:
在null上调用成员函数getContainer()
由此字符串触发:
return $kernel->getContainer();
如何在codeception中将全局$kernel对象传递给crawler(即FunctionalTester的实例)?全局变量是一种不好的做法。我可以假设,在运行测试时,codeception会创建自己的测试内核,并且该内核不能全局使用。这个地方需要重构重构遗留代码并将其从任何全局中清除是个好主意这是一种称为“接口”的方法吗?这不是一个接口。接口是PHP中的一个关键字,根本不应该这样使用。乔,我同意。谢谢你的建议。我正在“享受”重写遗留项目,有很多有趣的事情,这样的“接口调用程序”只是一个很长的例子。