Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Jun 14, 2024
1 parent fb9c2a3 commit f061817
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions tests/Testing/CustomAssertionsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
Expand All @@ -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']]];
Expand All @@ -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);
Expand All @@ -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']]];
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -169,9 +200,14 @@ public function testAssertHtmlTagCountWithResponse(): void
{
$html = '<html><div>One</div><div>Two</div><span>Not You</span><div>Three</div></html>';

/** @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');
Expand Down

0 comments on commit f061817

Please sign in to comment.