Skip to content

Commit

Permalink
Tidying up.
Browse files Browse the repository at this point in the history
  • Loading branch information
herloct committed Oct 13, 2016
1 parent 1be087a commit d48e1e1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Lib/Connector/Slim.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Herloct\Codeception\Lib\Connector;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UploadedFileInterface;
use Slim\App;
Expand Down Expand Up @@ -41,13 +42,16 @@ public function setApp(App $app)
protected function doRequest($request)
{
$slimRequest = $this->convertRequest($request);

$container = $this->app->getContainer();

$slimResponse = $this->app->process(
$slimRequest,
$container->get('response')
->withBody(new Stream(fopen('php://temp', 'w+')))
);
/* @var $slimResponse ResponseInterface */
$slimResponse = $container->get('response');

// reset body stream
$slimResponse = $slimResponse->withBody(new Stream(fopen('php://temp', 'w+')));

$slimResponse = $this->app->process($slimRequest, $slimResponse);

return new BrowserKitResponse(
(string) $slimResponse->getBody(),
Expand All @@ -65,13 +69,15 @@ protected function doRequest($request)
private function convertRequest(BrowserKitRequest $request)
{
$environment = Environment::mock($request->getServer());
$container = $this->app->getContainer();

$uri = Uri::createFromString($request->getUri());
$headers = Headers::createFromEnvironment($environment);
$cookies = Cookies::parseHeader($headers->get('Cookie', []));

$container = $this->app->getContainer();

/* @var $slimRequest ServerRequestInterface */
$slimRequest = $container->get('request');

$slimRequest = $slimRequest->withMethod($request->getMethod())
->withUri($uri)
->withUploadedFiles($this->convertFiles($request->getFiles()))
Expand Down

0 comments on commit d48e1e1

Please sign in to comment.