Skip to content

Commit

Permalink
Add notModified method to HTTP client (#48379)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot committed Sep 13, 2023
1 parent 5f78beb commit ece34f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Http/Client/Concerns/DeterminesStatusCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public function found()
return $this->status() === 302;
}

/**
* Determine if the response code was a 304 "Not Modified" response.
*
* @return bool
*/
public function notModified()
{
return $this->status() === 304;
}

/**
* Determine if the response was a 400 "Bad Request" response.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/Http/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ protected function setUp(): void
protected function tearDown(): void
{
m::close();

parent::tearDown();
}

public function testStubbedResponsesAreReturnedAfterFaking()
Expand Down Expand Up @@ -133,6 +135,20 @@ public function testFoundRequest()
$this->assertFalse($response->found());
}

public function testNotModifiedRequest(): void
{
$this->factory->fake([
'vapor.laravel.com' => $this->factory::response('', HttpResponse::HTTP_NOT_MODIFIED),
'forge.laravel.com' => $this->factory::response('', HttpResponse::HTTP_OK),
]);

$response = $this->factory->post('https://vapor.laravel.com');
$this->assertTrue($response->notModified());

$response = $this->factory->post('https://forge.laravel.com');
$this->assertFalse($response->notModified());
}

public function testBadRequestRequest()
{
$this->factory->fake([
Expand Down

0 comments on commit ece34f1

Please sign in to comment.