Skip to content

Commit 3f9ff7f

Browse files
Create ApplicationWrapperTest.php
1 parent 8fdde46 commit 3f9ff7f

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

test/ApplicationWrapperTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace PHPFastCGI\Test\Expressive;
4+
5+
use PHPFastCGI\Adapter\Expressive\ApplicationWrapper;
6+
use PHPFastCGI\FastCGIDaemon\Http\Request;
7+
use Zend\Expressive\AppFactory;
8+
9+
/**
10+
* Tests the application wrapper.
11+
*/
12+
class ApplicationWrapperTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* Tests that requests are passed through the wrapper correctly.
16+
*/
17+
public function testHandleRequest()
18+
{
19+
// Create the Expressive app
20+
$app = AppFactory::create();
21+
22+
// Add a simple route to the app
23+
$app->get('/test', function ($request, $response, $next) {
24+
$response->getBody()->write('Hello, World!');
25+
return $response;
26+
});
27+
28+
// Create a kernel for the FastCGI daemon using the Expressive app
29+
$kernel = new ApplicationWrapper($app);
30+
31+
// Create a request to test the route set up for the app
32+
$stream = fopen('php://temp', 'r');
33+
$request = new Request(['REQUEST_URI' => '/test'], $stream);
34+
35+
// Get the response from the kernel that is wrapping the app
36+
$response = $kernel->handleRequest($request);
37+
38+
// Check that the app has been wrapper properly by comparing to expected response
39+
$this->assertSame('Hello, World!', (string) $response->getBody());
40+
41+
fclose($stream);
42+
}
43+
}

0 commit comments

Comments
 (0)