Crud\Test\TestCase\Listener\ApiListenerTest::testExceptionResponse PHP Method

testExceptionResponse() public method

Test _exceptionResponse
public testExceptionResponse ( array $apiConfig, string $exceptionClass, string $exceptionMessage, integer $exceptionCode, array $validationErrors = [] ) : void
$apiConfig array
$exceptionClass string
$exceptionMessage string
$exceptionCode integer
$validationErrors array
return void
    public function testExceptionResponse($apiConfig, $exceptionClass, $exceptionMessage, $exceptionCode, $validationErrors = [])
    {
        $listener = $this->getMockBuilder('\\Crud\\Listener\\ApiListener')->disableOriginalConstructor()->setMethods(null)->getMock();
        $event = new \Cake\Event\Event('Crud.Exception', new \Crud\Event\Subject());
        if (isset($apiConfig['type']) && $apiConfig['type'] === 'validate') {
            $event->subject->set(['entity' => $this->getMockBuilder('\\Cake\\ORM\\Entity')->setMethods(['errors'])->getMock()]);
            $event->subject->entity->expects($this->any())->method('errors')->will($this->returnValue($validationErrors));
        }
        $this->setExpectedException($exceptionClass, $exceptionMessage, $exceptionCode);
        $this->setReflectionClassInstance($listener);
        $this->callProtectedMethod('_exceptionResponse', [$event, $apiConfig], $listener);
    }