summaryrefslogtreecommitdiff
path: root/tests/Unit/Http/MessageTraitResponseTest.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-03 22:43:19 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-03 22:55:54 +0200
commit36dafdb68acbde2fe42ce36ef50f497c8c06411f (patch)
tree1e420597ae72c979361bf29b66ae7e27c73cf431 /tests/Unit/Http/MessageTraitResponseTest.php
parent9f1ee0c6c6497d43fb275491ec53fda420f64b81 (diff)
parentb0e7bc0df2eb4975223582089c7a928903e8cd14 (diff)
Merge remote-tracking branch 'MyIgel/rebuild-psr7'
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());
+ }
+}