Skip to content

Commit

Permalink
Report invalid action response as an assertion failure
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgaber committed Oct 11, 2020
1 parent 83c63ee commit 1437b1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Actions/MockActionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use JoshGaber\NovaUnit\Constraints\IsActionResponseType;
use PHPUnit\Framework\Assert as PHPUnit;
use PHPUnit\Framework\Constraint\IsType;

class MockActionResponse
{
private $response;

public function __construct($response)
public function __construct($response = null)
{
$this->response = $response;
}
Expand All @@ -25,7 +26,10 @@ public function assertResponseType(string $type, string $message = ''): self
{
PHPUnit::assertThat(
$this->response,
new IsActionResponseType($type),
PHPUnit::logicalAnd(
new IsType('array'),
new IsActionResponseType($type)
),
$message
);

Expand Down
7 changes: 7 additions & 0 deletions tests/Feature/Actions/MockActionResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,11 @@ public function testItFailsWhenThereIsNoDangerMessage()
$mockActionResponse = new MockActionResponse(Action::message('Test Message'));
$mockActionResponse->assertDangerContains('test');
}

public function testItFailsOnNoResponse()
{
$this->shouldFail();
$mockActionResponse = new MockActionResponse();
$mockActionResponse->assertResponseType('message');
}
}

0 comments on commit 1437b1a

Please sign in to comment.