Skip to content

Commit

Permalink
Add support for Laravel 11 (#28)
Browse files Browse the repository at this point in the history
* Add support for Laravel 11
* Add support for PHP 8.3
* Drop support for PHP 7.4
* Update package dependencies
* Update PHP Unit configuration
* Update the test codes from using doc-comment metadata to use PHP 8 attribute
* Update Github actions workflow's configuration
* Update readme
  • Loading branch information
richan-fongdasen authored Mar 13, 2024
1 parent a35d740 commit d365927
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 140 deletions.
60 changes: 34 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,38 @@ name: Build

on:
push:
paths-ignore: ['*.md']
paths-ignore: ["*.md"]
pull_request:
paths-ignore: [ '*.md' ]
branches: [ main, 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, soap, intl, gd, exif, iconv
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-cacheable-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: Install composer dependencies
run: composer install --no-interaction --prefer-dist
- name: Run static analysis
Expand All @@ -42,57 +44,63 @@ jobs:
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" "larastan/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-cacheable-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, soap, intl, gd, exif, iconv
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" "larastan/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-cacheable-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 Coverage test suite
Expand Down
19 changes: 8 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@
"source": "https://github.com/suitmedia/laravel-cacheable"
},
"require": {
"php": "^7.4|^8.0",
"illuminate/cache": "^8.0|^9.0|^10.0",
"illuminate/database": "^8.0|^9.0|^10.0",
"illuminate/support": "^8.0|^9.0|^10.0"
"php": "^8.0",
"illuminate/cache": "^8.0|^9.0|^10.0|^11.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",
"fakerphp/faker": "^1.14",
"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.0",
"phpmd/phpmd": "^2.11",
"phpstan/phpstan-deprecation-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 @@ -65,8 +63,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-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="Cacheable Test Suite">
<directory suffix="Tests.php">./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
63 changes: 32 additions & 31 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[![Build](https://github.com/suitmedia/laravel-cacheable/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/suitmedia/laravel-cacheable/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/suitmedia/laravel-cacheable/branch/master/graph/badge.svg)](https://codecov.io/gh/suitmedia/laravel-cacheable)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/suitmedia/laravel-cacheable/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/suitmedia/laravel-cacheable/?branch=master)
[![Total Downloads](https://poser.pugx.org/suitmedia/laravel-cacheable/d/total.svg)](https://packagist.org/packages/suitmedia/laravel-cacheable)
[![Latest Stable Version](https://poser.pugx.org/suitmedia/laravel-cacheable/v/stable.svg)](https://packagist.org/packages/suitmedia/laravel-cacheable)
[![License: MIT](https://poser.pugx.org/laravel/framework/license.svg)](https://opensource.org/licenses/MIT)
[![Build](https://github.com/suitmedia/laravel-cacheable/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/suitmedia/laravel-cacheable/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/suitmedia/laravel-cacheable/branch/master/graph/badge.svg)](https://codecov.io/gh/suitmedia/laravel-cacheable)
[![Total Downloads](https://poser.pugx.org/suitmedia/laravel-cacheable/d/total.svg)](https://packagist.org/packages/suitmedia/laravel-cacheable)
[![Latest Stable Version](https://poser.pugx.org/suitmedia/laravel-cacheable/v/stable.svg)](https://packagist.org/packages/suitmedia/laravel-cacheable)
[![License: MIT](https://poser.pugx.org/laravel/framework/license.svg)](https://opensource.org/licenses/MIT)

# Laravel Cacheable

Expand All @@ -15,24 +14,25 @@ This package will help you to make your repositories cacheable without worrying

## Table of contents

* [Compatibility](#compatibility)
* [Requirements](#requirements)
* [Setup](#setup)
* [Configuration](#configuration)
* [Usage](#usage)
* [License](#license)
- [Compatibility](#compatibility)
- [Requirements](#requirements)
- [Setup](#setup)
- [Configuration](#configuration)
- [Usage](#usage)
- [License](#license)

## Compatibility

Laravel version | Cacheable version
:------------------|:-----------------
5.1.x - 5.4.x | 1.0.x - 1.3.x
5.5.x - 5.8.x | 1.4.x
6.x | 1.5.x
7.x | 1.6.x
8.x | 1.7.x
9.x | 1.9.x - 1.10.x
10.x | 1.11.x
| Laravel version | Cacheable version |
| :-------------- | :---------------- |
| 5.1.x - 5.4.x | 1.0.x - 1.3.x |
| 5.5.x - 5.8.x | 1.4.x |
| 6.x | 1.5.x |
| 7.x | 1.6.x |
| 8.x | 1.7.x |
| 9.x | 1.9.x - 1.10.x |
| 10.x | 1.11.x |
| 11.x | 1.12.x |

## Requirements

Expand All @@ -41,6 +41,7 @@ This package require you to use cache storage which supports tags like memcached
## Setup

Install the package via Composer :

```sh
$ composer require suitmedia/laravel-cacheable
```
Expand All @@ -49,7 +50,7 @@ $ composer require suitmedia/laravel-cacheable
### Register The Service Provider

Add the package service provider in your ``config/app.php``
Add the package service provider in your `config/app.php`

```php
'providers' => [
Expand All @@ -60,7 +61,7 @@ Add the package service provider in your ``config/app.php``

### Register The Package Alias

Add the package alias in your ``config/app.php``
Add the package alias in your `config/app.php`

```php
'aliases' => [
Expand All @@ -71,13 +72,13 @@ Add the package alias in your ``config/app.php``

## Configuration

Publish configuration file using ``php artisan`` command
Publish configuration file using `php artisan` command

```sh
$ php artisan vendor:publish --provider="Suitmedia\Cacheable\ServiceProvider"
```

The command above would copy a new configuration file to ``/config/cacheable.php``
The command above would copy a new configuration file to `/config/cacheable.php`

```php
return [
Expand Down Expand Up @@ -181,7 +182,7 @@ class ArticleRepository implements CacheableRepository
| Repository's method definition starts from here
|--------------------------------------------------------------------------
*/

public function all()
{
return $this->model->all();
Expand All @@ -197,10 +198,10 @@ class ArticleRepository implements CacheableRepository
#### Retrieve Data From Repository And Cache The Result

With this package, you won't need to create new classes to decorate each of your repositories. You can just decorate them using the `Cacheable` facade, and all results of the repository's methods will be cached automatically.

```php
// Lets decorate the repository first
$repo = \Cacheable::wrap(ArticleRepository::class);
$repo = Cacheable::wrap(ArticleRepository::class);

// The result of these codes will be cached automatically
$repo->all();
Expand All @@ -215,14 +216,14 @@ But, you can also invalidate the cache manually using the `Cacheable` facade.

```php
// Flush everything
\Cacheable::flush();
Cacheable::flush();

// Flush the cache using a specific tag
\Cacheable::flush('Article');
Cacheable::flush('Article');

// Flush the cache using a specific tag,
// and only for the cache which belongs to a specific user
\Cacheable::flush('LikedArticle:User:7');
Cacheable::flush('LikedArticle:User:7');
```

## License
Expand Down
3 changes: 2 additions & 1 deletion src/CacheableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Cache\CacheManager;
use Illuminate\Cache\TaggableStore;
use Illuminate\Contracts\Cache\Store;
use Illuminate\Support\Facades\App;
use Suitmedia\Cacheable\Contracts\CacheableRepository;

class CacheableService
Expand Down Expand Up @@ -151,7 +152,7 @@ protected function taggedCache(Store $cache, $tags)
public function wrap($repository): CacheableDecorator
{
if (is_string($repository)) {
$repository = \App::make($repository);
$repository = App::make($repository);
}

return $this->wrapWithDecorator($repository);
Expand Down
11 changes: 6 additions & 5 deletions tests/CacheableEventTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Suitmedia\Cacheable\Tests;

use PHPUnit\Framework\Attributes\Test;
use Suitmedia\Cacheable\Events\CacheableInvalidating;
use Suitmedia\Cacheable\Tests\Supports\Models\Video;

Expand All @@ -26,10 +27,10 @@ class CacheableEventTests extends TestCase
*
* @return void
*/
public function setUp() :void
public function setUp(): void
{
parent::setUp();

$this->model = new Video;
$this->event = new CacheableInvalidating(
$this->model,
Expand All @@ -38,7 +39,7 @@ public function setUp() :void
);
}

/** @test */
#[Test]
public function return_affected_fields_correctly()
{
$actual = $this->event->affectedFields();
Expand All @@ -47,15 +48,15 @@ public function return_affected_fields_correctly()
$this->assertEquals($expected, $actual);
}

/** @test */
#[Test]
public function return_affected_model_correctly()
{
$actual = $this->event->model();

$this->assertEquals($this->model, $actual);
}

/** @test */
#[Test]
public function return_invalidate_tags_correctly()
{
$actual = $this->event->tags();
Expand Down
Loading

0 comments on commit d365927

Please sign in to comment.