Skip to content

Commit

Permalink
Adds conflict status assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Jan 25, 2023
1 parent 3e4bc0a commit c522830
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Testing/Concerns/AssertsStatusCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ public function assertRequestTimeout()
return $this->assertStatus(408);
}

/**
* Assert that the response has a conflict status code.
*
* @return $this
*/
public function assertConflict()
{
return $this->assertStatus(409);
}

/**
* Assert that the response has a 422 status code.
*
Expand Down
19 changes: 19 additions & 0 deletions tests/Testing/TestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,25 @@ public function testAssertFound()
$this->fail();
}

public function testAssertConflict()
{
$response = TestResponse::fromBaseResponse(
(new Response)->setStatusCode(Response::HTTP_CONFLICT)
);

$response->assertConflict();

$response = TestResponse::fromBaseResponse(
(new Response)->setStatusCode(Response::HTTP_OK)
);

$this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage("Expected response status code [409] but received 200.\nFailed asserting that 409 is identical to 200.");

$response->assertConflict();
$this->fail();
}

public function testAssertAccepted()
{
$response = TestResponse::fromBaseResponse(
Expand Down

0 comments on commit c522830

Please sign in to comment.