From f061817829a20d6b2f05fad3a4a920a0fd8fb64d Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Thu, 13 Jun 2024 21:58:18 -0400 Subject: [PATCH] Fix tests --- tests/Testing/CustomAssertionsTraitTest.php | 50 ++++++++++++++++++--- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/tests/Testing/CustomAssertionsTraitTest.php b/tests/Testing/CustomAssertionsTraitTest.php index 69fcffe..39e3323 100644 --- a/tests/Testing/CustomAssertionsTraitTest.php +++ b/tests/Testing/CustomAssertionsTraitTest.php @@ -17,6 +17,7 @@ use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; use UserFrosting\Testing\CustomAssertionsTrait; /** @@ -34,9 +35,14 @@ class CustomAssertionsTraitTest extends TestCase public function testAssertResponse(): void { + /** @var StreamInterface $stream */ + $stream = Mockery::mock(StreamInterface::class) + ->shouldReceive('__toString')->andReturn('foo bar') + ->getMock(); + /** @var ResponseInterface $response */ $response = Mockery::mock(ResponseInterface::class) - ->shouldReceive('getBody')->once()->andReturn('foo bar') + ->shouldReceive('getBody')->once()->andReturn($stream) ->getMock(); $this->assertResponse('foo bar', $response); @@ -55,9 +61,14 @@ public function testAssertResponseStatus(): void /** @depends testAssertJsonEquals */ public function testAssertJsonResponse(): void { + /** @var StreamInterface $stream */ + $stream = Mockery::mock(StreamInterface::class) + ->shouldReceive('__toString')->andReturn($this->json) + ->getMock(); + /** @var ResponseInterface $response */ $response = Mockery::mock(ResponseInterface::class) - ->shouldReceive('getBody')->times(2)->andReturn($this->json) + ->shouldReceive('getBody')->times(2)->andReturn($stream) ->getMock(); $array = ['result' => ['foo' => true, 'bar' => false, 'list' => ['foo', 'bar']]]; @@ -68,9 +79,14 @@ public function testAssertJsonResponse(): void /** @depends testAssertJsonNotEquals */ public function testAssertNotJsonResponse(): void { + /** @var StreamInterface $stream */ + $stream = Mockery::mock(StreamInterface::class) + ->shouldReceive('__toString')->andReturn($this->json) + ->getMock(); + /** @var ResponseInterface $response */ $response = Mockery::mock(ResponseInterface::class) - ->shouldReceive('getBody')->times(3)->andReturn($this->json) + ->shouldReceive('getBody')->times(3)->andReturn($stream) ->getMock(); $this->assertNotJsonResponse(['foo'], $response); @@ -96,9 +112,14 @@ public function testAssertJsonNotEquals(): void public function testAssertJsonEqualsWithResponse(): void { + /** @var StreamInterface $stream */ + $stream = Mockery::mock(StreamInterface::class) + ->shouldReceive('__toString')->andReturn($this->json) + ->getMock(); + /** @var ResponseInterface $response */ $response = Mockery::mock(ResponseInterface::class) - ->shouldReceive('getBody')->times(3)->andReturn($this->json) + ->shouldReceive('getBody')->times(3)->andReturn($stream) ->getMock(); $array = ['result' => ['foo' => true, 'bar' => false, 'list' => ['foo', 'bar']]]; @@ -116,9 +137,14 @@ public function testAssertJsonStructure(): void public function testAssertJsonStructureWithResponse(): void { + /** @var StreamInterface $stream */ + $stream = Mockery::mock(StreamInterface::class) + ->shouldReceive('__toString')->andReturn($this->json) + ->getMock(); + /** @var ResponseInterface $response */ $response = Mockery::mock(ResponseInterface::class) - ->shouldReceive('getBody')->times(2)->andReturn($this->json) + ->shouldReceive('getBody')->times(2)->andReturn($stream) ->getMock(); $this->assertJsonStructure(['result'], $response); @@ -140,9 +166,14 @@ public function testAssertJsonCount(): void public function testAssertJsonCountWithResponse(): void { + /** @var StreamInterface $stream */ + $stream = Mockery::mock(StreamInterface::class) + ->shouldReceive('__toString')->andReturn($this->json) + ->getMock(); + /** @var ResponseInterface $response */ $response = Mockery::mock(ResponseInterface::class) - ->shouldReceive('getBody')->times(3)->andReturn($this->json) + ->shouldReceive('getBody')->times(3)->andReturn($stream) ->getMock(); $this->assertJsonCount(1, $response); @@ -169,9 +200,14 @@ public function testAssertHtmlTagCountWithResponse(): void { $html = '
One
Two
Not You
Three
'; + /** @var StreamInterface $stream */ + $stream = Mockery::mock(StreamInterface::class) + ->shouldReceive('__toString')->andReturn($html) + ->getMock(); + /** @var ResponseInterface $response */ $response = Mockery::mock(ResponseInterface::class) - ->shouldReceive('getBody')->times(4)->andReturn($html) + ->shouldReceive('getBody')->times(4)->andReturn($stream) ->getMock(); $this->assertHtmlTagCount(3, $response, 'div');