public function testService($method, $parameters, $return, $emitNr, $signalClass = '', array $signalAttr = null)
{
$innerService = $this->getServiceMock();
$innerService->expects($this->once())->method($method)->will($this->returnValueMap(array(array_merge($parameters, array($return)))));
$dispatcher = $this->getMock('eZ\\Publish\\Core\\SignalSlot\\SignalDispatcher');
$that = $this;
$d = $dispatcher->expects($this->exactly($emitNr))->method('emit');
if ($emitNr && $signalClass && $signalAttr) {
$d->with($this->callback(function ($signal) use($that, $signalClass, $signalAttr) {
if (!$signal instanceof $signalClass) {
$that->fail("The signal is not an instance of {$signalClass}");
return false;
}
foreach ($signalAttr as $attr => $val) {
if ($signal->{$attr} !== $val) {
$that->fail("The attribute '{$attr}' of the signal does not have the correct value '{$val}'");
return false;
}
}
return true;
}));
}
$service = $this->getSignalSlotService($innerService, $dispatcher);
$result = call_user_func_array(array($service, $method), $parameters);
$this->assertTrue($result === $return);
}