summaryrefslogtreecommitdiff
path: root/tests/Unit
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-08-20 17:35:07 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-08-20 17:43:15 +0200
commitb0e7bc0df2eb4975223582089c7a928903e8cd14 (patch)
treecb822bbf31a0339f08df6131ce5fcdd87fa398db /tests/Unit
parent5427ee385dc2ff117a1130eb606f78e708949c8f (diff)
Made Engelsystem\Http\Request PSR-7 ServerRequestInterface compatible
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/Http/Psr7ServiceProviderTest.php5
-rw-r--r--tests/Unit/Http/RequestTest.php183
2 files changed, 183 insertions, 5 deletions
diff --git a/tests/Unit/Http/Psr7ServiceProviderTest.php b/tests/Unit/Http/Psr7ServiceProviderTest.php
index a09e9572..e14daf2a 100644
--- a/tests/Unit/Http/Psr7ServiceProviderTest.php
+++ b/tests/Unit/Http/Psr7ServiceProviderTest.php
@@ -50,11 +50,6 @@ class Psr7ServiceProviderTest extends ServiceProviderTest
[ResponseInterface::class, 'psr7.response']
);
- $psr7Factory->expects($this->once())
- ->method('createRequest')
- ->with($request)
- ->willReturn($psr7request);
-
$serviceProvider = new Psr7ServiceProvider($app);
$serviceProvider->register();
}
diff --git a/tests/Unit/Http/RequestTest.php b/tests/Unit/Http/RequestTest.php
index f7d69aff..916aac35 100644
--- a/tests/Unit/Http/RequestTest.php
+++ b/tests/Unit/Http/RequestTest.php
@@ -6,7 +6,9 @@ use Engelsystem\Http\Request;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\UploadedFileInterface;
use Psr\Http\Message\UriInterface;
+use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyFile;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
class RequestTest extends TestCase
@@ -196,4 +198,185 @@ class RequestTest extends TestCase
$this->assertInstanceOf(UriInterface::class, $uri);
$this->assertEquals('http://lor.em/test?bla=foo', (string)$uri);
}
+
+ /**
+ * @covers \Engelsystem\Http\Request::getServerParams
+ */
+ public function testGetServerParams()
+ {
+ $server = ['foo' => 'bar'];
+ $request = new Request([], [], [], [], [], $server);
+
+ $this->assertEquals($server, $request->getServerParams());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::getCookieParams
+ */
+ public function testGetCookieParams()
+ {
+ $cookies = ['session' => 'LoremIpsumDolorSit'];
+ $request = new Request([], [], [], $cookies);
+
+ $this->assertEquals($cookies, $request->getCookieParams());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::withCookieParams
+ */
+ public function testWithCookieParams()
+ {
+ $cookies = ['lor' => 'em'];
+ $request = new Request();
+
+ $new = $request->withCookieParams($cookies);
+
+ $this->assertNotEquals($request, $new);
+ $this->assertEquals($cookies, $new->getCookieParams());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::getQueryParams
+ */
+ public function testGetQueryParams()
+ {
+ $params = ['foo' => 'baz'];
+ $request = new Request($params);
+
+ $this->assertEquals($params, $request->getQueryParams());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::withQueryParams
+ */
+ public function testWithQueryParams()
+ {
+ $params = ['test' => 'ing'];
+ $request = new Request();
+
+ $new = $request->withQueryParams($params);
+
+ $this->assertNotEquals($request, $new);
+ $this->assertEquals($params, $new->getQueryParams());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::getUploadedFiles
+ */
+ public function testGetUploadedFiles()
+ {
+ $filename = tempnam(sys_get_temp_dir(), 'test');
+ file_put_contents($filename, 'LoremIpsum!');
+ $files = [new SymfonyFile($filename, 'foo.html', 'text/html', 11)];
+ $request = new Request([], [], [], [], $files);
+
+ $uploadedFiles = $request->getUploadedFiles();
+ $this->assertNotEmpty($uploadedFiles);
+
+ /** @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(11, $file->getSize());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::withUploadedFiles
+ */
+ public function testWithUploadedFiles()
+ {
+ $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');
+
+ $request = new Request();
+ $new = $request->withUploadedFiles([$file]);
+ $uploadedFiles = $new->getUploadedFiles();
+ $this->assertNotEquals($request, $new);
+ $this->assertNotEmpty($uploadedFiles);
+
+ /** @var UploadedFileInterface $file */
+ $file = $uploadedFiles[0];
+ $this->assertEquals('test.txt', $file->getClientFilename());
+ $this->assertEquals('text/plain', $file->getClientMediaType());
+ $this->assertEquals(11, $file->getSize());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::getParsedBody
+ */
+ public function testGetParsedBody()
+ {
+ $body = ['foo' => 'lorem'];
+ $request = new Request();
+ $request->request->add($body);
+
+ $this->assertEquals($body, $request->getParsedBody());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::withParsedBody
+ */
+ public function testWithParsedBody()
+ {
+ $data = ['test' => 'er'];
+ $request = new Request();
+
+ $new = $request->withParsedBody($data);
+
+ $this->assertNotEquals($request, $new);
+ $this->assertEquals($data, $new->getParsedBody());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::getAttributes
+ */
+ public function testGetAttributes()
+ {
+ $attributes = ['foo' => 'lorem', 'ipsum' => 'dolor'];
+ $request = new Request([], [], $attributes);
+
+ $this->assertEquals($attributes, $request->getAttributes());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::getAttribute
+ */
+ public function testGetAttribute()
+ {
+ $attributes = ['foo' => 'lorem', 'ipsum' => 'dolor'];
+ $request = new Request([], [], $attributes);
+
+ $this->assertEquals($attributes['ipsum'], $request->getAttribute('ipsum'));
+ $this->assertEquals(null, $request->getAttribute('dolor'));
+ $this->assertEquals(1234, $request->getAttribute('test', 1234));
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::withAttribute
+ */
+ public function testWithAttribute()
+ {
+ $request = new Request();
+
+ $new = $request->withAttribute('lorem', 'ipsum');
+
+ $this->assertNotEquals($request, $new);
+ $this->assertEquals('ipsum', $new->getAttribute('lorem'));
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::withoutAttribute
+ */
+ public function testWithoutAttribute()
+ {
+ $attributes = ['foo' => 'lorem', 'ipsum' => 'dolor'];
+ $request = new Request([], [], $attributes);
+
+ $new = $request->withoutAttribute('ipsum');
+
+ $this->assertNotEquals($request, $new);
+ $this->assertEquals(['foo' => 'lorem'], $new->getAttributes());
+ }
}