Zend\Mvc\MvcEvent::setError PHP Méthode

setError() public méthode

Set the error message (indicating error in handling request)
public setError ( string $message ) : MvcEvent
$message string
Résultat MvcEvent
    public function setError($message)
    {
        $this->setParam('error', $message);
        return $this;
    }

Usage Example

 /**
  * @covers ::onDispatchError
  */
 public function testOnDispatchErrorStoreAndStreamImage()
 {
     $id = 'someId';
     $resource = 'someResource';
     $this->event->setError(Application::ERROR_ROUTER_NO_MATCH);
     $image = $this->getMockBuilder(ImageEntity::class)->setMethods(['getLength', 'getResource'])->getMock();
     $image->setId($id);
     $image->setType('image/jpeg');
     $image->setName('image.jpg');
     $image->method('getLength')->willReturn(1024);
     $image->method('getResource')->willReturn($resource);
     $this->manager->expects($this->once())->method('matchUri')->willReturn($id);
     $this->repository->expects($this->once())->method('find')->with($this->equalTo($id))->willReturn($image);
     $this->manager->expects($this->once())->method('store')->with($this->identicalTo($image));
     $this->listener->onDispatchError($this->event);
     $response = $this->event->getResponse();
     $this->assertInstanceOf(Stream::class, $response);
     $this->assertEquals(Response::STATUS_CODE_200, $response->getStatusCode());
     $this->assertEquals($image->getName(), $response->getStreamName());
     $this->assertEquals($image->getResource(), $response->getStream());
     $headers = $response->getHeaders();
     $this->assertInstanceOf(Headers::class, $headers);
     $this->assertTrue($headers->has('Content-Type'));
     $this->assertEquals($image->getType(), $headers->get('Content-Type')->getFieldValue());
     $this->assertTrue($headers->has('Content-Length'));
     $this->assertEquals($image->getLength(), $headers->get('Content-Length')->getFieldValue());
 }
All Usage Examples Of Zend\Mvc\MvcEvent::setError