/** * @test */ public function logrefInResponseAndLogMatch() { foreach ([400, 500] as $code) { $logref = null; $logger = $this->getMockForAbstractClass('Psr\\Log\\LoggerInterface'); $logger->expects($this->once())->method($this->anything())->with($this->callback(function ($message) use(&$logref) { $matches = []; if (preg_match('/logref ([a-z0-9]*)/', $message, $matches)) { $logref = $matches[1]; return true; } return false; })); /** @var LoggerInterface $logger */ $this->exceptionListener->setLogger($logger); $this->codeProperty->setValue($this->exception, $code); $this->exceptionListener->onKernelException($this->event); $response = $this->event->getResponse(); $this->assertEquals($logref, json_decode($response->getContent())->logref); } }