summaryrefslogtreecommitdiff
path: root/tests/Unit/Http/MessageTraitResponseTest.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-08-16 18:13:53 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-08-19 14:04:16 +0200
commit5427ee385dc2ff117a1130eb606f78e708949c8f (patch)
treefdea2a1ffcf8b85bf32725f5479c8a781f059387 /tests/Unit/Http/MessageTraitResponseTest.php
parent18fd73a899602a473044013854a354254062ebd4 (diff)
Made Engelsystem\Http\Request PSR-7 RequestInterface compatible
Diffstat (limited to 'tests/Unit/Http/MessageTraitResponseTest.php')
-rw-r--r--tests/Unit/Http/MessageTraitResponseTest.php159
1 files changed, 159 insertions, 0 deletions
diff --git a/tests/Unit/Http/MessageTraitResponseTest.php b/tests/Unit/Http/MessageTraitResponseTest.php
new file mode 100644
index 00000000..f60360a3
--- /dev/null
+++ b/tests/Unit/Http/MessageTraitResponseTest.php
@@ -0,0 +1,159 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Http;
+
+use Engelsystem\Test\Unit\Http\Stub\MessageTraitResponseImplementation;
+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
+{
+ /**
+ * @covers \Engelsystem\Http\MessageTrait
+ */
+ public function testCreate()
+ {
+ $message = new MessageTraitResponseImplementation();
+ $this->assertInstanceOf(MessageInterface::class, $message);
+ $this->assertInstanceOf(SymfonyResponse::class, $message);
+ }
+
+ /**
+ * @covers \Engelsystem\Http\MessageTrait::getProtocolVersion
+ * @covers \Engelsystem\Http\MessageTrait::withProtocolVersion
+ */
+ public function testGetProtocolVersion()
+ {
+ $message = new MessageTraitResponseImplementation();
+ $newMessage = $message->withProtocolVersion('0.1');
+ $this->assertNotEquals($message, $newMessage);
+ $this->assertEquals('0.1', $newMessage->getProtocolVersion());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\MessageTrait::getHeaders
+ */
+ public function testGetHeaders()
+ {
+ $message = new MessageTraitResponseImplementation();
+ $newMessage = $message->withHeader('Foo', 'bar');
+
+ $this->assertNotEquals($message, $newMessage);
+ $this->assertArraySubset(['Foo' => ['bar']], $newMessage->getHeaders());
+
+ $newMessage = $message->withHeader('lorem', ['ipsum', 'dolor']);
+ $this->assertArraySubset(['lorem' => ['ipsum', 'dolor']], $newMessage->getHeaders());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\MessageTrait::hasHeader
+ */
+ public function testHasHeader()
+ {
+ $message = new MessageTraitResponseImplementation();
+ $this->assertFalse($message->hasHeader('test'));
+
+ $newMessage = $message->withHeader('test', '12345');
+ $this->assertTrue($newMessage->hasHeader('Test'));
+ $this->assertTrue($newMessage->hasHeader('test'));
+ }
+
+ /**
+ * @covers \Engelsystem\Http\MessageTrait::getHeader
+ */
+ public function testGetHeader()
+ {
+ $message = new MessageTraitResponseImplementation();
+ $newMessage = $message->withHeader('foo', 'bar');
+
+ $this->assertEquals(['bar'], $newMessage->getHeader('Foo'));
+ $this->assertEquals([], $newMessage->getHeader('LoremIpsum'));
+ }
+
+ /**
+ * @covers \Engelsystem\Http\MessageTrait::getHeaderLine
+ */
+ public function testGetHeaderLine()
+ {
+ $message = new MessageTraitResponseImplementation();
+ $newMessage = $message->withHeader('foo', ['bar', 'bla']);
+
+ $this->assertEquals('', $newMessage->getHeaderLine('Lorem-Ipsum'));
+ $this->assertEquals('bar,bla', $newMessage->getHeaderLine('Foo'));
+ }
+
+ /**
+ * @covers \Engelsystem\Http\MessageTrait::withHeader
+ */
+ public function testWithHeader()
+ {
+ $message = new MessageTraitResponseImplementation();
+ $newMessage = $message->withHeader('foo', 'bar');
+
+ $this->assertNotEquals($message, $newMessage);
+ $this->assertArraySubset(['foo' => ['bar']], $newMessage->getHeaders());
+
+ $newMessage = $newMessage->withHeader('Foo', ['lorem', 'ipsum']);
+ $this->assertArraySubset(['Foo' => ['lorem', 'ipsum']], $newMessage->getHeaders());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\MessageTrait::withAddedHeader
+ */
+ public function testWithAddedHeader()
+ {
+ $message = new MessageTraitResponseImplementation();
+ $newMessage = $message->withHeader('foo', 'bar');
+
+ $this->assertNotEquals($message, $newMessage);
+ $this->assertArraySubset(['foo' => ['bar']], $newMessage->getHeaders());
+
+ $newMessage = $newMessage->withAddedHeader('Foo', ['lorem', 'ipsum']);
+ $this->assertArraySubset(['Foo' => ['bar', 'lorem', 'ipsum']], $newMessage->getHeaders());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\MessageTrait::withoutHeader
+ */
+ public function testWithoutHeader()
+ {
+ $message = (new MessageTraitResponseImplementation())->withHeader('foo', 'bar');
+ $this->assertTrue($message->hasHeader('foo'));
+
+ $newMessage = $message->withoutHeader('Foo');
+ $this->assertNotEquals($message, $newMessage);
+ $this->assertFalse($newMessage->hasHeader('foo'));
+ }
+
+ /**
+ * @covers \Engelsystem\Http\MessageTrait::getBody
+ */
+ public function testGetBody()
+ {
+ $message = (new MessageTraitResponseImplementation())->setContent('Foo bar!');
+ $body = $message->getBody();
+
+ $this->assertInstanceOf(StreamInterface::class, $body);
+ $this->assertEquals('Foo bar!', $body->getContents());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\MessageTrait::withBody
+ */
+ public function testWithBody()
+ {
+ /** @var Stream $stream */
+ $stream = new Stream('php://memory', 'wb+');
+ $stream->write('Test content');
+ $stream->rewind();
+
+ $message = new MessageTraitResponseImplementation();
+ $newMessage = $message->withBody($stream);
+
+ $this->assertNotEquals($message, $newMessage);
+ $this->assertEquals('Test content', $newMessage->getContent());
+ }
+}