From d9f898a0bba0d44d8212ba2459f7c77808f02643 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 17 Mar 2019 18:17:33 +0100 Subject: Bugfix: Replaced Diactoros with Symfony PsrHttpFactory to use PhpExtended\HttpMessage implementation Prevents warnings that get converted to errors when run in dev mode --- tests/Unit/Http/MessageTraitRequestTest.php | 8 +--- tests/Unit/Http/MessageTraitResponseTest.php | 8 +--- tests/Unit/Http/Psr7ServiceProviderTest.php | 68 +++++++++++++--------------- tests/Unit/Http/RequestTest.php | 9 ++-- 4 files changed, 41 insertions(+), 52 deletions(-) (limited to 'tests') diff --git a/tests/Unit/Http/MessageTraitRequestTest.php b/tests/Unit/Http/MessageTraitRequestTest.php index 7430b5d7..c3d99afb 100644 --- a/tests/Unit/Http/MessageTraitRequestTest.php +++ b/tests/Unit/Http/MessageTraitRequestTest.php @@ -3,8 +3,8 @@ namespace Engelsystem\Test\Unit\Http; use Engelsystem\Test\Unit\Http\Stub\MessageTraitRequestImplementation; +use PhpExtended\HttpMessage\StringStream; use PHPUnit\Framework\TestCase; -use Zend\Diactoros\Stream; class MessageTraitRequestTest extends TestCase { @@ -36,11 +36,7 @@ class MessageTraitRequestTest extends TestCase */ public function testWithBody() { - /** @var Stream $stream */ - $stream = new Stream('php://memory', 'wb+'); - $stream->write('Test content'); - $stream->rewind(); - + $stream = new StringStream('Test content'); $message = new MessageTraitRequestImplementation(); $newMessage = $message->withBody($stream); diff --git a/tests/Unit/Http/MessageTraitResponseTest.php b/tests/Unit/Http/MessageTraitResponseTest.php index f60360a3..31b529ee 100644 --- a/tests/Unit/Http/MessageTraitResponseTest.php +++ b/tests/Unit/Http/MessageTraitResponseTest.php @@ -3,11 +3,11 @@ namespace Engelsystem\Test\Unit\Http; use Engelsystem\Test\Unit\Http\Stub\MessageTraitResponseImplementation; +use PhpExtended\HttpMessage\StringStream; use PHPUnit\Framework\TestCase; use Psr\Http\Message\MessageInterface; use Psr\Http\Message\StreamInterface; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; -use Zend\Diactoros\Stream; class MessageTraitResponseTest extends TestCase { @@ -145,11 +145,7 @@ class MessageTraitResponseTest extends TestCase */ public function testWithBody() { - /** @var Stream $stream */ - $stream = new Stream('php://memory', 'wb+'); - $stream->write('Test content'); - $stream->rewind(); - + $stream = new StringStream('Test content'); $message = new MessageTraitResponseImplementation(); $newMessage = $message->withBody($stream); diff --git a/tests/Unit/Http/Psr7ServiceProviderTest.php b/tests/Unit/Http/Psr7ServiceProviderTest.php index e14daf2a..25c2f6e3 100644 --- a/tests/Unit/Http/Psr7ServiceProviderTest.php +++ b/tests/Unit/Http/Psr7ServiceProviderTest.php @@ -2,14 +2,16 @@ namespace Engelsystem\Test\Unit\Http; +use Engelsystem\Application; 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\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface as RequestInterface; -use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; +use Psr\Http\Message\ServerRequestFactoryInterface; +use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Message\StreamFactoryInterface; +use Psr\Http\Message\UploadedFileFactoryInterface; +use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface; class Psr7ServiceProviderTest extends ServiceProviderTest { @@ -18,39 +20,33 @@ class Psr7ServiceProviderTest extends ServiceProviderTest */ 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'] - ); + $app = new Application; $serviceProvider = new Psr7ServiceProvider($app); $serviceProvider->register(); + + foreach ( + [ + 'psr7.factory.request', + 'psr7.factory.response', + 'psr7.factory.upload', + 'psr7.factory.stream', + 'psr7.factory', + 'psr7.request', + 'psr7.response', + ServerRequestFactoryInterface::class, + ResponseFactoryInterface::class, + UploadedFileFactoryInterface::class, + StreamFactoryInterface::class, + HttpMessageFactoryInterface::class, + ServerRequestInterface::class, + ResponseInterface::class, + ] as $id + ) { + $this->assertTrue( + $app->has($id), + sprintf('"%s" is not registered', $id) + ); + } } } diff --git a/tests/Unit/Http/RequestTest.php b/tests/Unit/Http/RequestTest.php index 11a8ed83..8210d583 100644 --- a/tests/Unit/Http/RequestTest.php +++ b/tests/Unit/Http/RequestTest.php @@ -3,6 +3,7 @@ namespace Engelsystem\Test\Unit\Http; use Engelsystem\Http\Request; +use PhpExtended\HttpMessage\UploadedFile; use PHPUnit\Framework\TestCase; use PHPUnit_Framework_MockObject_MockObject as MockObject; use Psr\Http\Message\RequestInterface; @@ -285,7 +286,7 @@ class RequestTest extends TestCase { $filename = tempnam(sys_get_temp_dir(), 'test'); file_put_contents($filename, 'LoremIpsum!'); - $files = [new SymfonyFile($filename, 'foo.html', 'text/html', 11)]; + $files = [new SymfonyFile($filename, 'foo.txt', 'text/plain', 11)]; $request = new Request([], [], [], [], $files); $uploadedFiles = $request->getUploadedFiles(); @@ -294,8 +295,8 @@ class RequestTest extends TestCase /** @var UploadedFileInterface $file */ $file = $uploadedFiles[0]; $this->assertInstanceOf(UploadedFileInterface::class, $file); - $this->assertEquals('foo.html', $file->getClientFilename()); - $this->assertEquals('text/html', $file->getClientMediaType()); + $this->assertEquals('foo.txt', $file->getClientFilename()); + $this->assertEquals('text/plain', $file->getClientMediaType()); $this->assertEquals(11, $file->getSize()); } @@ -306,7 +307,7 @@ class RequestTest extends TestCase { $filename = tempnam(sys_get_temp_dir(), 'test'); file_put_contents($filename, 'LoremIpsum!'); - $file = new \Zend\Diactoros\UploadedFile($filename, 11, UPLOAD_ERR_OK, 'test.txt', 'text/plain'); + $file = new UploadedFile('test.txt', $filename, 'text/plain', 11, UPLOAD_ERR_OK); $request = new Request(); $new = $request->withUploadedFiles([$file]); -- cgit v1.2.3-70-g09d2