Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Supports For Laravel 11 #28

Merged
merged 2 commits into from
Mar 13, 2024
Merged
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
80 changes: 44 additions & 36 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,105 @@ name: Build

on:
push:
paths-ignore: ['*.md']
paths-ignore: ["*.md"]
pull_request:
paths-ignore: [ '*.md' ]
branches: [ master ]
paths-ignore: ["*.md"]
branches: [main]

jobs:
analysis:
runs-on: ubuntu-latest
strategy:
matrix:
php: [8.2]
php: [8.3]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, gd, exif, iconv
coverage: none
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v2
uses: actions/cache@v4
env:
cache-name: laravel-varnishable-analysis
with:
path: ~/.composer
path: ${{ steps.composer-cache.outputs.dir }}
key: php-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
php-${{ matrix.php }}-build-${{ env.cache-name }}-
php-${{ matrix.php }}-build-
php-${{ matrix.php }}-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
coverage: none
- name: Install composer dependencies
run: composer install --no-interaction --prefer-dist
- name: Run statuc analysis
- name: Run static analysis
run: composer analyse
test:
name: Test (PHP ${{ matrix.php }})
needs: [analysis]
runs-on: ubuntu-latest
strategy:
matrix:
php: [7.4, 8.0, 8.1]
php: [8.0, 8.1, 8.2]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, gd, exif, iconv
coverage: none
- name: Remove some dev dependencies
run: composer remove "ekino/phpstan-banned-code" "nunomaduro/larastan" "phpmd/phpmd" "phpstan/phpstan-deprecation-rules" "sebastian/phpcpd" --dev --no-update
run: composer remove "ekino/phpstan-banned-code" "nunomaduro/larastan" "phpmd/phpmd" "phpstan/phpstan-deprecation-rules" --dev --no-update
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v2
uses: actions/cache@v4
env:
cache-name: laravel-varnishable-test
with:
path: ~/.composer
path: ${{ steps.composer-cache.outputs.dir }}
key: php-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
php-${{ matrix.php }}-build-${{ env.cache-name }}-
php-${{ matrix.php }}-build-
php-${{ matrix.php }}-
- name: Install composer dependencies
run: composer install --no-interaction --prefer-dist
- name: Run the test suite
run: vendor/bin/phpunit
test-coverage:
name: Test (PHP ${{ matrix.php }})
needs: [ analysis ]
needs: [analysis]
runs-on: ubuntu-latest
strategy:
matrix:
php: [ 8.2 ]
php: [8.3]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, gd, exif, iconv
- name: Remove some dev dependencies
run: composer remove "ekino/phpstan-banned-code" "nunomaduro/larastan" "phpmd/phpmd" "phpstan/phpstan-deprecation-rules" --dev --no-update
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v2
uses: actions/cache@v4
env:
cache-name: laravel-varnishable-test
with:
path: ~/.composer
path: ${{ steps.composer-cache.outputs.dir }}
key: php-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
php-${{ matrix.php }}-build-${{ env.cache-name }}-
php-${{ matrix.php }}-build-
php-${{ matrix.php }}-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
- name: Install composer dependencies
run: composer install --no-interaction --prefer-dist
- name: Run the Coverage test suite
Expand Down
17 changes: 7 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@
"source": "https://github.com/richan-fongdasen/laravel-varnishable"
},
"require": {
"php": "^7.4|^8.0",
"php": "^8.0",
"guzzlehttp/guzzle": "^7.0",
"illuminate/database": "^8.0|^9.0|^10.0",
"illuminate/support": "^8.0|^9.0|^10.0"
"illuminate/database": "^8.0|^9.0|^10.0|^11.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0"
},
"require-dev": {
"ekino/phpstan-banned-code": "^1.0",
"larastan/larastan": "^1.0|^2.0",
"mockery/mockery": "^1.4",
"nunomaduro/larastan": "^1.0|^2.0",
"orchestra/database": "^6.0|dev-master",
"orchestra/testbench": "^6.0|^7.0|^8.0",
"orchestra/testbench": "^6.0|^7.0|^8.0|9.x-dev",
"phpmd/phpmd": "^2.11",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5",
"sebastian/phpcpd": "^6.0"
"phpunit/phpunit": "^9.5|^10.0|^11.0"
},
"config": {
"sort-packages": true
Expand Down Expand Up @@ -66,8 +64,7 @@
"analyse": [
"composer check-syntax",
"composer phpstan-analysis",
"composer phpmd-analysis",
"vendor/bin/phpcpd --min-lines=3 --min-tokens=36 src/"
"composer phpmd-analysis"
],
"check-syntax": [
"! find src -type f -name \"*.php\" -exec php -l {} \\; | grep -v 'No syntax errors'",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- vendor/nunomaduro/larastan/extension.neon
- vendor/larastan/larastan/extension.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/ekino/phpstan-banned-code/extension.neon
Expand Down
12 changes: 6 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Laravel Varnishable Test Suite">
<directory suffix="Tests.php">./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build](https://github.com/richan-fongdasen/laravel-varnishable/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/richan-fongdasen/laravel-varnishable/actions/workflows/main.yml)
[![Build](https://github.com/richan-fongdasen/laravel-varnishable/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/richan-fongdasen/laravel-varnishable/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/richan-fongdasen/laravel-varnishable/branch/master/graph/badge.svg)](https://codecov.io/gh/richan-fongdasen/laravel-varnishable)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/richan-fongdasen/laravel-varnishable/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/richan-fongdasen/laravel-varnishable/?branch=master)
[![StyleCI Analysis Status](https://github.styleci.io/repos/135787392/shield?branch=master)](https://github.styleci.io/repos/135787392)
Expand Down Expand Up @@ -34,14 +34,15 @@ $ composer require richan-fongdasen/laravel-varnishable
### Laravel version compatibility

| Laravel version | Varnishable version |
|:----------------|:--------------------|
| :-------------- | :------------------ |
| 5.1.x - 5.4.x | 0.x |
| 5.5.x - 5.8.x | 1.0.x - 1.1.x |
| 6.x | 1.2.x |
| 7.x | 1.3.x |
| 8.x | ^1.4.x |
| 9.x | 2.0.x |
| 10.x | 2.1.x |
| 11.x | 2.2.x |

> If you are using Laravel version 5.5+ then you can skip registering the service provider in your Laravel application.

Expand Down
11 changes: 6 additions & 5 deletions tests/Concerns/InvalidateVarnishCacheTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Illuminate\Container\Container;
use PHPUnit\Framework\Attributes\Test;
use RichanFongdasen\Varnishable\Tests\TestCase;
use RichanFongdasen\Varnishable\VarnishableService;

Expand Down Expand Up @@ -36,7 +37,7 @@ class InvalidateVarnishCacheTests extends TestCase
*
* @return void
*/
public function setUp() :void
public function setUp(): void
{
parent::setUp();

Expand All @@ -49,7 +50,7 @@ public function setUp() :void
$this->response = Container::getInstance()->make(Response::class, []);
}

/** @test */
#[Test]
public function it_can_send_fullban_request_to_flush_the_entire_cache()
{
$options = ['headers' => ['X-Ban-Host' => 'localhost:8000']];
Expand All @@ -65,7 +66,7 @@ public function it_can_send_fullban_request_to_flush_the_entire_cache()
$this->service->flush('localhost:8000');
}

/** @test */
#[Test]
public function it_can_send_ban_requests_based_on_the_given_regex_patterns()
{
$options1 = ['headers' => [
Expand Down Expand Up @@ -96,7 +97,7 @@ public function it_can_send_ban_requests_based_on_the_given_regex_patterns()
]);
}

/** @test */
#[Test]
public function it_can_send_ban_requests_based_on_the_given_urls()
{
$options1 = ['headers' => [
Expand Down Expand Up @@ -127,7 +128,7 @@ public function it_can_send_ban_requests_based_on_the_given_urls()
]);
}

/** @test */
#[Test]
public function it_can_generate_varnish_url_correctly()
{
$actual = $this->invokeMethod($this->service, 'getVarnishUrl', ['localhost']);
Expand Down
11 changes: 6 additions & 5 deletions tests/Concerns/ManageEtagHeaderTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace RichanFongdasen\Varnishable\Tests\Concerns;

use Illuminate\Http\Response;
use PHPUnit\Framework\Attributes\Test;
use RichanFongdasen\Varnishable\Tests\TestCase;
use RichanFongdasen\Varnishable\VarnishableService;

Expand All @@ -27,7 +28,7 @@ class ManageEtagHeaderTests extends TestCase
*
* @return void
*/
public function setUp() :void
public function setUp(): void
{
parent::setUp();

Expand All @@ -37,7 +38,7 @@ public function setUp() :void
$this->service = app(VarnishableService::class);
}

/** @test */
#[Test]
public function it_can_add_an_etag_header_to_the_current_response_object()
{
$content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
Expand All @@ -47,10 +48,10 @@ public function it_can_add_an_etag_header_to_the_current_response_object()
$this->invokeMethod($this->service, 'addEtagHeader', [$this->response]);

$actual = $this->response->headers->get('etag');
$this->assertEquals('"'. md5($content) .'"', $actual);
$this->assertEquals('"' . md5($content) . '"', $actual);
}

/** @test */
#[Test]
public function it_can_disable_etag_header_at_runtime()
{
$this->service->enableEtag();
Expand All @@ -59,7 +60,7 @@ public function it_can_disable_etag_header_at_runtime()
$this->assertFalse($this->service->getConfig('use_etag'));
}

/** @test */
#[Test]
public function it_can_enable_etag_header_at_runtime()
{
$this->service->disableEtag();
Expand Down
13 changes: 7 additions & 6 deletions tests/Concerns/ManageLastModifiedHeaderTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use Illuminate\Http\Response;
use PHPUnit\Framework\Attributes\Test;
use RichanFongdasen\Varnishable\Tests\TestCase;
use RichanFongdasen\Varnishable\VarnishableService;

Expand All @@ -28,7 +29,7 @@ class ManageLastModifiedHeaderTests extends TestCase
*
* @return void
*/
public function setUp() :void
public function setUp(): void
{
parent::setUp();

Expand All @@ -38,7 +39,7 @@ public function setUp() :void
$this->service = app(VarnishableService::class);
}

/** @test */
#[Test]
public function it_can_add_last_modified_header_to_the_current_response_object()
{
$time = new Carbon('2018-07-16 23:00:00');
Expand All @@ -49,7 +50,7 @@ public function it_can_add_last_modified_header_to_the_current_response_object()
$this->assertEquals($time->toRfc7231String(), $this->response->headers->get('Last-Modified'));
}

/** @test */
#[Test]
public function it_can_disable_last_modified_header_at_runtime()
{
$this->service->enableLastModified();
Expand All @@ -58,7 +59,7 @@ public function it_can_disable_last_modified_header_at_runtime()
$this->assertFalse($this->service->getConfig('use_last_modified'));
}

/** @test */
#[Test]
public function it_can_enable_last_modified_header_at_runtime()
{
$this->service->disableLastModified();
Expand All @@ -67,7 +68,7 @@ public function it_can_enable_last_modified_header_at_runtime()
$this->assertTrue($this->service->getConfig('use_last_modified'));
}

/** @test */
#[Test]
public function it_returns_last_modified_value_correctly()
{
$time = new Carbon('2018-07-16 23:00:00');
Expand All @@ -80,7 +81,7 @@ public function it_returns_last_modified_value_correctly()
$this->assertEquals($time->getTimestamp(), $actual->getTimestamp());
}

/** @test */
#[Test]
public function it_can_set_last_modified_header_with_the_newest_timestamp()
{
$times = [
Expand Down
Loading