eZ\Bundle\EzPublishRestBundle\Tests\EventListener\EventListenerTest::getRequestMock PHP Method

getRequestMock() protected method

protected getRequestMock ( ) : PHPUnit_Framework_MockObject_MockObjec\PHPUnit_Framework_MockObject_MockObject | Request
return PHPUnit_Framework_MockObject_MockObjec\PHPUnit_Framework_MockObject_MockObject | Symfony\Component\HttpFoundation\Request
    protected function getRequestMock()
    {
        if (!isset($this->requestMock)) {
            $this->requestMock = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
            $this->requestMock->attributes = $this->getRequestAttributesMock();
            $this->requestMock->headers = $this->getRequestHeadersMock();
            if ($this->requestMethod === false) {
                $this->requestMock->expects($this->never())->method('getMethod');
            } else {
                $this->requestMock->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue($this->requestMethod));
            }
        }
        return $this->requestMock;
    }

Usage Example

 /**
  * @return PHPUnit_Framework_MockObject_MockObject|Request
  */
 protected function getRequestMock()
 {
     if (!isset($this->requestMock)) {
         $this->requestMock = parent::getRequestMock();
         if ($this->sessionMock === false) {
             $this->requestMock->expects($this->never())->method('getSession');
         } else {
             $this->requestMock->expects($this->atLeastOnce())->method('getSession')->will($this->returnValue($this->getSessionMock()));
         }
         if ($this->route === false) {
             $this->requestMock->expects($this->never())->method('get');
         } else {
             $this->requestMock->expects($this->atLeastOnce())->method('get')->with('_route')->will($this->returnValue($this->route));
         }
     }
     return $this->requestMock;
 }