Skip to content

Commit 7e2db33

Browse files
Updated to use FastCGIDaemon v0.6.*
1 parent 2e0e5ea commit 7e2db33

File tree

5 files changed

+71
-108
lines changed

5 files changed

+71
-108
lines changed

Bridge/KernelWrapper.php

+7-21
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,37 @@
22

33
namespace PHPFastCGI\SpeedfonyBundle\Bridge;
44

5+
use PHPFastCGI\FastCGIDaemon\Http\RequestInterface;
56
use PHPFastCGI\FastCGIDaemon\KernelInterface;
6-
use Psr\Http\Message\ServerRequestInterface;
7-
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
8-
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
97
use Symfony\Component\HttpKernel\Kernel;
108

119
class KernelWrapper implements KernelInterface
1210
{
1311
/**
1412
* @var Kernel
1513
*/
16-
protected $kernel;
17-
18-
/**
19-
* @var HttpFoundationFactoryInterface
20-
*/
21-
protected $symfonyMessageFactory;
22-
23-
/**
24-
* @var HttpMessageFactoryInterface
25-
*/
26-
protected $psrMessageFactory;
14+
private $kernel;
2715

2816
/**
2917
* Constructor.
3018
*
3119
* @param Kernel $kernel
3220
*/
33-
public function __construct(Kernel $kernel, HttpFoundationFactoryInterface $symfonyMessageFactory, HttpMessageFactoryInterface $psrMessageFactory)
21+
public function __construct(Kernel $kernel)
3422
{
35-
$this->kernel = $kernel;
36-
$this->symfonyMessageFactory = $symfonyMessageFactory;
37-
$this->psrMessageFactory = $psrMessageFactory;
23+
$this->kernel = $kernel;
3824
}
3925

4026
/**
4127
* {@inheritdoc}
4228
*/
43-
public function handleRequest(ServerRequestInterface $request)
29+
public function handleRequest(RequestInterface $request)
4430
{
45-
$symfonyRequest = $this->symfonyMessageFactory->createRequest($request);;
31+
$symfonyRequest = $request->getHttpFoundationRequest();
4632

4733
$symfonyResponse = $this->kernel->handle($symfonyRequest);
4834
$this->kernel->terminate($symfonyRequest, $symfonyResponse);
4935

50-
return $this->psrMessageFactory->createResponse($symfonyResponse);
36+
return $symfonyResponse;
5137
}
5238
}

Resources/config/services.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
services:
2-
php_fast_cgi_speedfony.symfony_message_factory:
3-
class: Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory
4-
5-
php_fast_cgi_speedfony.psr_message_factory:
6-
class: Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory
7-
82
php_fast_cgi_speedfony.kernel_wrapper:
93
class: PHPFastCGI\SpeedfonyBundle\Bridge\KernelWrapper
10-
arguments: ['@kernel', '@php_fast_cgi_speedfony.symfony_message_factory', '@php_fast_cgi_speedfony.psr_message_factory']
4+
arguments: ['@kernel']
115

126
php_fast_cgi_speedfony.daemon_run_command:
137
class: PHPFastCGI\FastCGIDaemon\Command\DaemonRunCommand

Tests/Bridge/KernelWrapperTest.php

+12-78
Original file line numberDiff line numberDiff line change
@@ -2,97 +2,31 @@
22

33
namespace PHPFastCGI\SpeedfonyBundle\Tests\Bridge;
44

5+
use PHPFastCGI\FastCGIDaemon\Http\Request;
56
use PHPFastCGI\SpeedfonyBundle\Bridge\KernelWrapper;
6-
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
7-
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
8-
use Symfony\Component\HttpFoundation\Request;
9-
use Symfony\Component\HttpFoundation\Response;
10-
use Symfony\Component\HttpKernel\Kernel;
11-
use Symfony\Component\Config\Loader\LoaderInterface;
12-
use Zend\Diactoros\ServerRequestFactory;
7+
use PHPFastCGI\SpeedfonyBundle\Tests\Helper\MockKernel;
8+
use Symfony\Component\HttpFoundation\Request as HttpFoundationRequest;
9+
use Symfony\Component\HttpFoundation\Response as HttpFoundationResponse;
1310

1411
class KernelWrapperTest extends \PHPUnit_Framework_TestCase
1512
{
1613
public function testKernelWrapper()
1714
{
18-
$globals = array(
19-
'server' => array(
20-
'REQUEST_URI' => '/uri'
21-
),
22-
'query' => array(
23-
'foo' => 'bar'
24-
),
25-
'post' => array(
26-
'bar' => 'foo'
27-
)
28-
);
15+
$stream = fopen('php://temp', 'r');
16+
$request = new Request(['REQUEST_URI' => '/hello'], $stream);
2917

30-
$psrRequest = ServerRequestFactory::fromGlobals($globals['server'], $globals['query'], $globals['post']);
31-
$symfonyResponse = new Response('Hello World');
18+
$symfonyResponse = new HttpFoundationResponse('Hello World');
3219

33-
$kernel = new MockKernel(function (Request $symfonyRequest) use ($globals, $symfonyResponse) {
34-
$this->assertEquals($globals['server'], $symfonyRequest->server->all());
35-
$this->assertEquals($globals['query'], $symfonyRequest->query->all());
36-
$this->assertEquals($globals['post'], $symfonyRequest->request->all());
37-
38-
$this->assertEquals($globals['server']['REQUEST_URI'], $symfonyRequest->getRequestUri());
20+
$kernel = new MockKernel(function (HttpFoundationRequest $symfonyRequest) use ($symfonyResponse) {
21+
$this->assertEquals('/hello', $symfonyRequest->getRequestUri());
3922

4023
return $symfonyResponse;
4124
});
4225

43-
$kernelWrapper = new KernelWrapper($kernel, new HttpFoundationFactory(), new DiactorosFactory());
44-
45-
$psrResponse = $kernelWrapper->handleRequest($psrRequest);
46-
47-
$this->assertEquals($symfonyResponse->getContent(), (string) $psrResponse->getBody());
48-
$this->assertEquals($symfonyResponse->getStatusCode(), $psrResponse->getStatusCode());
49-
}
50-
}
51-
52-
class MockKernel extends Kernel
53-
{
54-
/**
55-
* @var callable
56-
*/
57-
protected $callback;
58-
59-
/**
60-
* Constructor.
61-
*
62-
* @param callable $callback
63-
*/
64-
public function __construct($callback)
65-
{
66-
$this->callback = $callback;
67-
68-
parent::__construct('dev', false);
69-
}
70-
71-
/**
72-
* {@inheritdoc}
73-
*/
74-
public function registerBundles()
75-
{
76-
return [];
77-
}
78-
79-
/**
80-
* {@inheritdoc}
81-
*/
82-
public function registerContainerConfiguration(LoaderInterface $loader)
83-
{
84-
}
85-
86-
/**
87-
* {@inheritdoc}
88-
*/
89-
public function handle(Request $request, $type = 1, $catch = true)
90-
{
91-
return call_user_func($this->callback, $request);
26+
$kernelWrapper = new KernelWrapper($kernel);
9227

93-
$psrResponse = $kernelWrapper->handleRequest($psrRequest);
28+
$this->assertEquals($symfonyResponse, $kernelWrapper->handleRequest($request));
9429

95-
$this->assertEquals($symfonyResponse->getContent(), (string) $psrResponse->getBody());
96-
$this->assertEquals($symfonyResponse->getStatusCode(), $psrResponse->getStatusCode());
30+
fclose($stream);
9731
}
9832
}

Tests/Helper/MockKernel.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace PHPFastCGI\SpeedfonyBundle\Tests\Helper;
4+
5+
use Symfony\Component\Config\Loader\LoaderInterface;
6+
use Symfony\Component\HttpFoundation\Request;
7+
use Symfony\Component\HttpKernel\Kernel;
8+
9+
class MockKernel extends Kernel
10+
{
11+
/**
12+
* @var callable
13+
*/
14+
private $callback;
15+
16+
/**
17+
* Constructor.
18+
*
19+
* @param callable $callback
20+
*/
21+
public function __construct($callback)
22+
{
23+
$this->callback = $callback;
24+
25+
parent::__construct('dev', false);
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function registerBundles()
32+
{
33+
return [];
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function registerContainerConfiguration(LoaderInterface $loader)
40+
{
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function handle(Request $request, $type = 1, $catch = true)
47+
{
48+
return call_user_func($this->callback, $request);
49+
}
50+
}

composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"require": {
1414
"php": ">=5.5.0",
1515
"symfony/symfony": "~2.7",
16-
"symfony/psr-http-message-bridge": "~0.1",
17-
"phpfastcgi/fastcgi-daemon": "0.5.*"
16+
"phpfastcgi/fastcgi-daemon": "0.6.*"
1817
},
1918
"require-dev": {
2019
"satooshi/php-coveralls": "dev-master"

0 commit comments

Comments
 (0)