Added Http\Response and Psr7{Request,Response}
This commit is contained in:
parent
2f41b9e441
commit
3c08829205
|
@ -22,7 +22,9 @@
|
||||||
"psr/container": "^1.0",
|
"psr/container": "^1.0",
|
||||||
"psr/log": "^1.0",
|
"psr/log": "^1.0",
|
||||||
"symfony/http-foundation": "^3.3",
|
"symfony/http-foundation": "^3.3",
|
||||||
"twbs/bootstrap": "^3.3"
|
"symfony/psr-http-message-bridge": "^1.0",
|
||||||
|
"twbs/bootstrap": "^3.3",
|
||||||
|
"zendframework/zend-diactoros": "^1.7"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"filp/whoops": "^2.1",
|
"filp/whoops": "^2.1",
|
||||||
|
|
|
@ -13,5 +13,7 @@ return [
|
||||||
\Engelsystem\Database\DatabaseServiceProvider::class,
|
\Engelsystem\Database\DatabaseServiceProvider::class,
|
||||||
\Engelsystem\Http\RequestServiceProvider::class,
|
\Engelsystem\Http\RequestServiceProvider::class,
|
||||||
\Engelsystem\Http\SessionServiceProvider::class,
|
\Engelsystem\Http\SessionServiceProvider::class,
|
||||||
|
\Engelsystem\Http\ResponseServiceProvider::class,
|
||||||
|
\Engelsystem\Http\Psr7ServiceProvider::class,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Http;
|
||||||
|
|
||||||
|
use Engelsystem\Container\ServiceProvider;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
|
||||||
|
|
||||||
|
|
||||||
|
class Psr7ServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
/** @var DiactorosFactory $psr7Factory */
|
||||||
|
$psr7Factory = $this->app->make(DiactorosFactory::class);
|
||||||
|
$this->app->instance('psr7.factory', $psr7Factory);
|
||||||
|
|
||||||
|
/** @var Request $request */
|
||||||
|
$request = $this->app->get('request');
|
||||||
|
$psr7request = $psr7Factory->createRequest($request);
|
||||||
|
$this->app->instance('psr7.request', $psr7request);
|
||||||
|
$this->app->bind(ServerRequestInterface::class, 'psr7.request');
|
||||||
|
|
||||||
|
/** @var Response $response */
|
||||||
|
$response = $this->app->get('response');
|
||||||
|
$psr7response = $psr7Factory->createResponse($response);
|
||||||
|
$this->app->instance('psr7.response', $psr7response);
|
||||||
|
$this->app->bind(ResponseInterface::class, 'psr7.response');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Http;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
|
||||||
|
|
||||||
|
class Response extends SymfonyResponse
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Http;
|
||||||
|
|
||||||
|
use Engelsystem\Container\ServiceProvider;
|
||||||
|
|
||||||
|
class ResponseServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$response = $this->app->make(Response::class);
|
||||||
|
$this->app->instance('response', $response);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Test\Unit\Http;
|
||||||
|
|
||||||
|
use Engelsystem\Http\Psr7ServiceProvider;
|
||||||
|
use Engelsystem\Http\Request;
|
||||||
|
use Engelsystem\Http\Response;
|
||||||
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
||||||
|
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface as RequestInterface;
|
||||||
|
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
|
||||||
|
|
||||||
|
class Psr7ServiceProviderTest extends ServiceProviderTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Http\Psr7ServiceProvider::register()
|
||||||
|
*/
|
||||||
|
public function testRegister()
|
||||||
|
{
|
||||||
|
/** @var MockObject|DiactorosFactory $psr7Factory */
|
||||||
|
$psr7Factory = $this->createMock(DiactorosFactory::class);
|
||||||
|
/** @var MockObject|Request $request */
|
||||||
|
$request = $this->createMock(Request::class);
|
||||||
|
/** @var MockObject|Response $response */
|
||||||
|
$response = $this->createMock(Response::class);
|
||||||
|
/** @var MockObject|RequestInterface $psr7request */
|
||||||
|
$psr7request = $this->createMock(Request::class);
|
||||||
|
/** @var MockObject|ResponseInterface $psr7response */
|
||||||
|
$psr7response = $this->createMock(Response::class);
|
||||||
|
|
||||||
|
$app = $this->getApp(['make', 'instance', 'get', 'bind']);
|
||||||
|
$this->setExpects($app, 'make', [DiactorosFactory::class], $psr7Factory);
|
||||||
|
|
||||||
|
$app->expects($this->atLeastOnce())
|
||||||
|
->method('get')
|
||||||
|
->withConsecutive(['request'], ['response'])
|
||||||
|
->willReturnOnConsecutiveCalls($request, $response);
|
||||||
|
$app->expects($this->atLeastOnce())
|
||||||
|
->method('instance')
|
||||||
|
->withConsecutive(
|
||||||
|
['psr7.factory', $psr7Factory],
|
||||||
|
['psr7.request', $psr7request],
|
||||||
|
['psr7.response', $psr7response]
|
||||||
|
);
|
||||||
|
$app->expects($this->atLeastOnce())
|
||||||
|
->method('bind')
|
||||||
|
->withConsecutive(
|
||||||
|
[RequestInterface::class, 'psr7.request'],
|
||||||
|
[ResponseInterface::class, 'psr7.response']
|
||||||
|
);
|
||||||
|
|
||||||
|
$psr7Factory->expects($this->once())
|
||||||
|
->method('createRequest')
|
||||||
|
->with($request)
|
||||||
|
->willReturn($psr7request);
|
||||||
|
$psr7Factory->expects($this->once())
|
||||||
|
->method('createResponse')
|
||||||
|
->with($response)
|
||||||
|
->willReturn($psr7response);
|
||||||
|
|
||||||
|
$serviceProvider = new Psr7ServiceProvider($app);
|
||||||
|
$serviceProvider->register();
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,9 +5,19 @@ namespace Engelsystem\Test\Unit\Http;
|
||||||
use Engelsystem\Http\Request;
|
use Engelsystem\Http\Request;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
||||||
|
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
|
||||||
|
|
||||||
class RequestTest extends TestCase
|
class RequestTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Http\Request
|
||||||
|
*/
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$response = new Request();
|
||||||
|
$this->assertInstanceOf(SymfonyRequest::class, $response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Engelsystem\Http\Request::postData
|
* @covers \Engelsystem\Http\Request::postData
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Test\Unit\Http;
|
||||||
|
|
||||||
|
use Engelsystem\Http\Response;
|
||||||
|
use Engelsystem\Http\ResponseServiceProvider;
|
||||||
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
||||||
|
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
||||||
|
|
||||||
|
class ResponseServiceProviderTest extends ServiceProviderTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Http\ResponseServiceProvider::register()
|
||||||
|
*/
|
||||||
|
public function testRegister()
|
||||||
|
{
|
||||||
|
/** @var MockObject|Response $response */
|
||||||
|
$response = $this->getMockBuilder(Response::class)
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$app = $this->getApp();
|
||||||
|
|
||||||
|
$this->setExpects($app, 'make', [Response::class], $response);
|
||||||
|
$this->setExpects($app, 'instance', ['response', $response]);
|
||||||
|
|
||||||
|
$serviceProvider = new ResponseServiceProvider($app);
|
||||||
|
$serviceProvider->register();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Test\Unit\Http;
|
||||||
|
|
||||||
|
use Engelsystem\Http\Response;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
|
||||||
|
|
||||||
|
class ResponseTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Http\Response
|
||||||
|
*/
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$response = new Response();
|
||||||
|
$this->assertInstanceOf(SymfonyResponse::class, $response);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue