部分测试对象:
class AddOptionsProviderArgumentPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if(!$container->hasDefinition('gremo_highcharts')) {
return;
}
if(!$container->hasParameter('gremo_highcharts.options_provider')) {
return;
}
// ...
}
}
我想断言:
hasDefinition()
使用参数“gremo_highcharts”调用将返回false
- 方法
process()
返回,即不会调用其他方法
一种解决方案是断言后续调用hasParameter()
:
public function testProcessWillReturnIfThereIsNoServiceDefinition()
{
$container = $this->getMockedContainerBuilder();
$pass = new AddOptionsProviderArgumentPass();
$container->expects($this->once())
->method('hasDefinition')
->with($this->equalTo('gremo_highcharts'))
->will($this->returnValue(false));
// Expects that hasParameter() is never invoked
$container->expects($this->never())
->method('hasParameter');
$pass->process($container);
}
但这似乎不是一个优雅的解决方案。