public function testBodyMutatorReturnsCloneWithChanges() { $stream = $this->getMock('Psr\\Http\\Message\\StreamInterface'); $message = $this->message->withBody($stream); $this->assertNotSame($this->message, $message); $this->assertSame($stream, $message->getBody()); }
public function testWithBody() { $mockBody = Mockery::mock(StreamInterface::class); $messageWithBody = $this->message->withBody($mockBody); static::assertNull($this->message->getBody()); // return null // The body MUST be a StreamInterface object. static::assertNotSame($this->message, $messageWithBody); // This method MUST be implemented in such a way as to retain the // immutability of the message, and MUST return a new instance that has the // new body stream. static::assertInstanceOf(StreamInterface::class, $messageWithBody->getBody()); static::assertSame($mockBody, $messageWithBody->getBody()); }
/** * {@inheritdoc} */ public function withBody(StreamInterface $body) { $new = clone $this; $new->message = $this->message->withBody($body); return $new; }