Skip to content

Commit e3c5426

Browse files
Updated to work with PHPFastCGI v0.6
1 parent 23a2905 commit e3c5426

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": ">=5.5.0",
1414
"slim/slim": "^3.0@beta",
15-
"phpfastcgi/fastcgi-daemon": "0.5.*"
15+
"phpfastcgi/fastcgi-daemon": "0.6.*"
1616
},
1717
"require-dev": {
1818
"satooshi/php-coveralls": "dev-master"

src/AppWrapper.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPFastCGI\Slimmer;
44

5+
use PHPFastCGI\FastCGIDaemon\Http\RequestInterface;
56
use PHPFastCGI\FastCGIDaemon\KernelInterface;
67
use Psr\Http\Message\ResponseInterface;
78
use Psr\Http\Message\ServerRequestInterface;
@@ -43,18 +44,20 @@ public function __construct(App $app)
4344
/**
4445
* {@inheritdoc}
4546
*/
46-
public function handleRequest(ServerRequestInterface $request)
47+
public function handleRequest(RequestInterface $request)
4748
{
49+
$serverRequest = $request->getServerRequest();
50+
4851
$headers = new Headers(['Content-Type' => 'text/html']);
4952
$response = (new Response(200, $headers))->withProtocolVersion('1.1');
5053

5154
try {
52-
$response = $this->app->callMiddlewareStack($request, $response);
55+
$response = $this->app->callMiddlewareStack($serverRequest, $response);
5356
} catch (SlimException $exception) {
5457
$response = $exception->getResponse();
5558
} catch (\Exception $exception) {
5659
$errorHandler = $this->container->get('errorHandler');
57-
$response = $errorHandler($request, $response, $exception);
60+
$response = $errorHandler($serverRequest, $response, $exception);
5861
}
5962

6063
return $this->finalizeResponse($response);

test/AppWrapperTest.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace PHPFastCGI\Test\Slimmer;
44

5+
use PHPFastCGI\FastCGIDaemon\Http\Request;
56
use PHPFastCGI\Slimmer\AppWrapper;
67
use Slim\App;
78
use Slim\Exception\Exception as SlimException;
89
use Zend\Diactoros\Response\HtmlResponse;
9-
use Zend\Diactoros\ServerRequest;
1010

1111
/**
1212
* Tests the app wrapper.
@@ -31,13 +31,16 @@ public function testHandleRequest()
3131
$kernel = new AppWrapper($app);
3232

3333
// Create a request to test the route set up for the app
34-
$request = new ServerRequest([], [], '/hello/Andrew');
34+
$stream = fopen('php://temp', 'r');
35+
$request = new Request(['REQUEST_URI' => '/hello/Andrew'], $stream);
3536

3637
// Get the response from the kernel that is wrapping the app
3738
$response = $kernel->handleRequest($request);
3839

3940
// Check that the app has been wrapper properly by comparing to expected response
4041
$this->assertSame('Hello, Andrew', (string) $response->getBody());
42+
43+
fclose($stream);
4144
}
4245

4346
/**
@@ -61,13 +64,16 @@ public function testSlimException()
6164
$kernel = new AppWrapper($app);
6265

6366
// Create a request to test the route set up for the app
64-
$request = new ServerRequest([], [], '/hello/Andrew');
67+
$stream = fopen('php://temp', 'r');
68+
$request = new Request(['REQUEST_URI' => '/hello/Andrew'], $stream);
6569

6670
// Get the response from the kernel that is wrapping the app
6771
$response = $kernel->handleRequest($request);
6872

6973
// Check that the app has been wrapper properly by comparing to expected response
7074
$this->assertEquals((string) $expectedResponse->getBody(), (string) $response->getBody());
75+
76+
fclose($stream);
7177
}
7278

7379
/**
@@ -87,13 +93,16 @@ public function testException()
8793
$kernel = new AppWrapper($app);
8894

8995
// Create a request to test the route set up for the app
90-
$request = new ServerRequest([], [], '/hello/Andrew');
96+
$stream = fopen('php://temp', 'r');
97+
$request = new Request(['REQUEST_URI' => '/hello/Andrew'], $stream);
9198

9299
// Get the response from the kernel that is wrapping the app
93100
$response = $kernel->handleRequest($request);
94101

95102
// Check that the app has returned a valid response
96103
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
104+
105+
fclose($stream);
97106
}
98107

99108
/**
@@ -118,7 +127,8 @@ public function testStrippedContentHeaders()
118127
$kernel = new AppWrapper($app);
119128

120129
// Create a request to test the route set up for the app
121-
$request = new ServerRequest([], [], '/hello/Andrew');
130+
$stream = fopen('php://temp', 'r');
131+
$request = new Request(['REQUEST_URI' => '/hello/Andrew'], $stream);
122132

123133
// Get the response from the kernel that is wrapping the app
124134
$response = $kernel->handleRequest($request);
@@ -127,5 +137,7 @@ public function testStrippedContentHeaders()
127137
$this->assertEquals('Hello', (string) $response->getBody());
128138
$this->assertFalse($response->hasHeader('Content-Type'));
129139
$this->assertFalse($response->hasHeader('Content-Length'));
140+
141+
fclose($stream);
130142
}
131143
}

0 commit comments

Comments
 (0)