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
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build:
environment:
php:
version: 8.1
version: 8.3.28
nodes:
analysis:
project_setup:
Expand Down
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
}
],
"homepage": "https://github.com/werk365/etagconditionals",
"keywords": ["Laravel", "EtagConditionals"],
"keywords": [
"Laravel",
"EtagConditionals"
],
"require": {
"illuminate/support": "~7|~8|~9|~10|~11|~12"
"illuminate/support": "~7|~8|~9|~10|~11|~12|^13.0"
},
"require-dev": {
"phpunit/phpunit": "~8.0|~9.0",
"orchestra/testbench": "~5|~6|~7|~8"
"phpunit/phpunit": "^12.0",
"orchestra/testbench": "~5|~6|~7|~8|^11.0"
},
"autoload": {
"psr-4": {
Expand Down
21 changes: 11 additions & 10 deletions tests/EtagConditionalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@

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

class EtagConditionalsTest extends TestCase
final class EtagConditionalsTest extends TestCase
{
private string $response = 'OK';

public function tearDown(): void
protected function tearDown(): void
{
EtagConditionals::etagGenerateUsing(null);
}

/** @test */
public function get_default_etag()
#[Test]
public function get_default_etag(): void
{
$request = Request::create('/', 'GET');
$response = response($this->response, 200);

$this->assertEquals('"e0aa021e21dddbd6d8cecec71e9cf564"', EtagConditionals::getEtag($request, $response));
}

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

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

/** @test */
public function get_etag_with_callback_with_quotes()
#[Test]
public function get_etag_with_callback_with_quotes(): void
{
$request = Request::create('/', 'GET');
$response = response($this->response, 200);
Expand Down
33 changes: 17 additions & 16 deletions tests/IfMatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

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

class IfMatchTest extends TestCase
final class IfMatchTest extends TestCase
{
private string $response = 'OK';

public function setUp(): void
protected function setUp(): void
{
parent::setUp();

Expand All @@ -19,8 +20,8 @@ public function setUp(): void
});
}

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

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

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

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

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

/** @test */
public function patch_request_returns_200_if_matching_weaktag_when_weak_is_enabled_in_config()
#[Test]
public function patch_request_returns_200_if_matching_weaktag_when_weak_is_enabled_in_config(): void
{
Config::set('etagconditionals.if_match_weak', true);
$ifMatch = 'W/"'.md5($this->response).'"';
Expand All @@ -92,8 +93,8 @@ public function patch_request_returns_200_if_matching_weaktag_when_weak_is_enabl
$response->assertStatus(200);
}

/** @test */
public function patch_request_returns_412_if_matching_weaktag_when_weak_is_disabled_in_config()
#[Test]
public function patch_request_returns_412_if_matching_weaktag_when_weak_is_disabled_in_config(): void
{
Config::set('etagconditionals.if_match_weak', false);
$ifMatch = 'W/"'.md5($this->response).'"';
Expand Down
21 changes: 11 additions & 10 deletions tests/IfNoneMatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

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

class IfNoneMatchTest extends TestCase
final class IfNoneMatchTest extends TestCase
{
private string $response = 'OK';

public function setUp(): void
protected function setUp(): void
{
parent::setUp();

Expand All @@ -19,8 +20,8 @@ public function setUp(): void
});
}

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

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

/** @test */
public function get_request_status_200_with_matching_weaktag_if_weak_is_disabled_in_config()
#[Test]
public function get_request_status_200_with_matching_weaktag_if_weak_is_disabled_in_config(): void
{
Config::set('etagconditionals.if_none_match_weak', false);
$noneMatch = 'W/"'.md5($this->response).'"';
Expand All @@ -56,8 +57,8 @@ public function get_request_status_200_with_matching_weaktag_if_weak_is_disabled
$response->assertStatus(200);
}

/** @test */
public function get_request_status_304_with_matching_weaktag_if_weak_is_enabled_in_config()
#[Test]
public function get_request_status_304_with_matching_weaktag_if_weak_is_enabled_in_config(): void
{
Config::set('etagconditionals.if_none_match_weak', true);
$noneMatch = 'W/"'.md5($this->response).'"';
Expand Down
13 changes: 7 additions & 6 deletions tests/SetEtagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Werk365\EtagConditionals\Tests;

use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Werk365\EtagConditionals\Middleware\SetEtag;

class SetEtagTest extends TestCase
final class SetEtagTest extends TestCase
{
private string $response = 'OK';

public function setUp(): void
protected function setUp(): void
{
parent::setUp();

Expand All @@ -18,15 +19,15 @@ public function setUp(): void
});
}

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

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