Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
"homepage": "https://github.com/werk365/etagconditionals",
"keywords": ["Laravel", "EtagConditionals"],
"require": {
"illuminate/support": "~7|~8|~9|~10"
"php": "^8.2",
"illuminate/support": "^10.0|^11.0|^12.0"
},
"require-dev": {
"phpunit/phpunit": "~8.0|~9.0",
"orchestra/testbench": "~5|~6|~7|~8"
"phpunit/phpunit": "^10.5|^11.0",
"orchestra/testbench": "^8.0|^9.0|^10.0"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 6 additions & 4 deletions tests/EtagConditionalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\HttpFoundation\Response;
use Werk365\EtagConditionals\EtagConditionals;

Expand All @@ -14,9 +15,10 @@ class EtagConditionalsTest extends TestCase
public function tearDown(): void
{
EtagConditionals::etagGenerateUsing(null);
parent::tearDown();
}

/** @test */
#[Test]
public function get_default_etag()
{
$request = Request::create('/', 'GET');
Expand All @@ -25,7 +27,7 @@ public function get_default_etag()
$this->assertEquals('"e0aa021e21dddbd6d8cecec71e9cf564"', EtagConditionals::getEtag($request, $response));
}

/** @test */
#[Test]
public function get_etag_with_callback_md5()
{
$request = Request::create('/', 'GET');
Expand All @@ -38,7 +40,7 @@ public function get_etag_with_callback_md5()
$this->assertEquals('"e0aa021e21dddbd6d8cecec71e9cf564"', EtagConditionals::getEtag($request, $response));
}

/** @test */
#[Test]
public function get_etag_with_callback_sophisticated()
{
$request = Request::create('/', 'GET');
Expand All @@ -51,7 +53,7 @@ public function get_etag_with_callback_sophisticated()
$this->assertEquals('"sophisticated"', EtagConditionals::getEtag($request, $response));
}

/** @test */
#[Test]
public function get_etag_with_callback_with_quotes()
{
$request = Request::create('/', 'GET');
Expand Down
16 changes: 9 additions & 7 deletions tests/IfMatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Werk365\EtagConditionals\Tests;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Route;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Werk365\EtagConditionals\Middleware\IfMatch;

class IfMatchTest extends TestCase
Expand All @@ -14,12 +16,12 @@ public function setUp(): void
{
parent::setUp();

\Route::middleware(IfMatch::class)->any('/_test/if-match', function () {
Route::middleware(IfMatch::class)->any('/_test/if-match', function () {
return response($this->response, 200);
});
}

/** @test */
#[Test]
public function patch_request_returns_200_if_matching_IfMatch()
{
$ifMatch = '"'.md5($this->response).'"';
Expand All @@ -31,7 +33,7 @@ public function patch_request_returns_200_if_matching_IfMatch()
$response->assertStatus(200);
}

/** @test */
#[Test]
public function patch_request_returns_200_if_matching_IfMatch_in_list_of_etags()
{
$ifMatch = '"'.md5('first').'", "'.md5($this->response).'","'.md5('last').'"';
Expand All @@ -43,7 +45,7 @@ public function patch_request_returns_200_if_matching_IfMatch_in_list_of_etags()
$response->assertStatus(200);
}

/** @test */
#[Test]
public function patch_request_returns_200_if_wildcard_is_used()
{
$ifMatch = '"'.md5('first').'", "*","'.md5('last').'"';
Expand All @@ -55,7 +57,7 @@ public function patch_request_returns_200_if_wildcard_is_used()
$response->assertStatus(200);
}

/** @test */
#[Test]
public function patch_request_returns_412_if_none_matching_IfMatch()
{
$ifMatch = '"'.md5($this->response.'ifMatch').'"';
Expand All @@ -67,7 +69,7 @@ public function patch_request_returns_412_if_none_matching_IfMatch()
$response->assertStatus(412);
}

/** @test */
#[Test]
public function patch_request_returns_412_if_none_matching_IfMatch_in_list_of_etags()
{
$ifMatch = '"'.md5('first').'", "'.md5($this->response.'ifMatch').'","'.md5('last').'"';
Expand All @@ -79,7 +81,7 @@ public function patch_request_returns_412_if_none_matching_IfMatch_in_list_of_et
$response->assertStatus(412);
}

/** @test */
#[Test]
public function patch_request_returns_200_if_matching_weaktag_when_weak_is_enabled_in_config()
{
Config::set('etagconditionals.if_match_weak', true);
Expand Down
12 changes: 7 additions & 5 deletions tests/IfNoneMatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Werk365\EtagConditionals\Tests;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Route;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Werk365\EtagConditionals\Middleware\IfNoneMatch;

class IfNoneMatchTest extends TestCase
Expand All @@ -14,12 +16,12 @@ public function setUp(): void
{
parent::setUp();

\Route::middleware(IfNoneMatch::class)->any('/_test/if-none-match', function () {
Route::middleware(IfNoneMatch::class)->any('/_test/if-none-match', function () {
return response($this->response, 200);
});
}

/** @test */
#[Test]
public function get_request_status_200_with_none_matching_IfNoneMatch()
{
$noneMatch = '"'.md5($this->response.'NoneMatch').'"';
Expand All @@ -31,7 +33,7 @@ public function get_request_status_200_with_none_matching_IfNoneMatch()
$response->assertStatus(200);
}

/** @test */
#[Test]
public function get_request_status_304_with_matching_IfNoneMatch()
{
$noneMatch = '"'.md5($this->response).'"';
Expand All @@ -43,7 +45,7 @@ public function get_request_status_304_with_matching_IfNoneMatch()
$response->assertStatus(304);
}

/** @test */
#[Test]
public function get_request_status_200_with_matching_weaktag_if_weak_is_disabled_in_config()
{
Config::set('etagconditionals.if_none_match_weak', false);
Expand All @@ -56,7 +58,7 @@ public function get_request_status_200_with_matching_weaktag_if_weak_is_disabled
$response->assertStatus(200);
}

/** @test */
#[Test]
public function get_request_status_304_with_matching_weaktag_if_weak_is_enabled_in_config()
{
Config::set('etagconditionals.if_none_match_weak', true);
Expand Down
8 changes: 5 additions & 3 deletions tests/SetEtagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Werk365\EtagConditionals\Tests;

use Illuminate\Support\Facades\Route;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Werk365\EtagConditionals\Middleware\SetEtag;

class SetEtagTest extends TestCase
Expand All @@ -13,19 +15,19 @@ public function setUp(): void
{
parent::setUp();

\Route::middleware(SetEtag::class)->any('/_test/set-etag', function () {
Route::middleware(SetEtag::class)->any('/_test/set-etag', function () {
return $this->response;
});
}

/** @test */
#[Test]
public function middleware_sets_etag_header()
{
$response = $this->get('/_test/set-etag');
$response->assertHeader('ETag', $value = null);
}

/** @test */
#[Test]
public function etag_header_has_correct_value()
{
$value = '"'.md5($this->response).'"';
Expand Down