Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 38 |
ZF2 | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 38 |
setApplication($application) | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
doRequest($request) | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 30 |
|||
getZendRequest() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
<?php | |
namespace Codeception\Util\Connector; | |
use Symfony\Component\BrowserKit\Request; | |
use Symfony\Component\BrowserKit\Response; | |
use Zend\Http\Request as HttpRequest; | |
use Zend\Stdlib\Parameters; | |
use Zend\Uri\Http as HttpUri; | |
class ZF2 extends \Symfony\Component\BrowserKit\Client | |
{ | |
/** | |
* @var \Zend\Mvc\ApplicationInterface | |
*/ | |
protected $application; | |
/** | |
* @var \Zend\Http\PhpEnvironment\Request | |
*/ | |
protected $zendRequest; | |
/** | |
* @param \Zend\Mvc\ApplicationInterface $application | |
*/ | |
public function setApplication($application) | |
{ | |
$this->application = $application; | |
} | |
/** | |
* @param Request $request | |
* | |
* @return Response | |
* @throws \Exception | |
*/ | |
public function doRequest($request) | |
{ | |
$zendRequest = $this->application->getRequest(); | |
$zendResponse = $this->application->getResponse(); | |
$uri = new HttpUri($request->getUri()); | |
$queryString = $uri->getQuery(); | |
$method = $request->getMethod(); | |
if ($queryString) { | |
parse_str($queryString, $query); | |
} | |
if ($method == HttpRequest::METHOD_POST) { | |
$post = $request->getParameters(); | |
$zendRequest->setPost(new Parameters($post)); | |
} elseif ($method == HttpRequest::METHOD_GET) { | |
$query = $request->getParameters(); | |
$zendRequest->setQuery(new Parameters($query)); | |
} elseif ($method == HttpRequest::METHOD_PUT) { | |
$zendRequest->setContent($request->getContent()); | |
} | |
$zendRequest->setMethod($method); | |
$zendRequest->setUri($uri); | |
$this->application->run(); | |
$this->zendRequest = $zendRequest; | |
$exception = $this->application->getMvcEvent()->getParam('exception'); | |
if ($exception instanceof \Exception) { | |
throw $exception; | |
} | |
$response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray()); | |
return $response; | |
} | |
/** | |
* @return \Zend\Http\PhpEnvironment\Request | |
*/ | |
public function getZendRequest() | |
{ | |
return $this->zendRequest; | |
} | |
} |