Skip to content

Commit

Permalink
Add support for Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
richan-fongdasen committed Mar 13, 2024
1 parent 5ffb74c commit 4f28c32
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 103 deletions.
56 changes: 31 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,96 +2,102 @@ name: CI

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

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: eloquent-blameable-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 --prefer-dist
- name: Run static analysis
run: composer analyse
test:
name: Test (PHP ${{ matrix.php }})
needs: [ analysis ]
needs: [analysis]
runs-on: ubuntu-latest
strategy:
matrix:
php: [7.4, 8.0, 8.1]
php: [8.0, 8.1, 8.2]
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up 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: eloquent-blameable-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 PHPUnit tests
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:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up 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: 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: eloquent-blameable-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 PHPUnit tests and generate code coverage
Expand Down
21 changes: 9 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@
"source": "https://github.com/richan-fongdasen/eloquent-blameable"
},
"require": {
"php": "^7.4|^8.0",
"illuminate/database": "^8.0|^9.0|^10.0",
"illuminate/support": "^8.0|^9.0|^10.0"
"php": "^8.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",
"mockery/mockery": "^1.3",
"nunomaduro/larastan": "^1.0|^2.0",
"orchestra/database": "^6.0|dev-master",
"orchestra/testbench": "^6.0|^7.0|^8.0",
"larastan/larastan": "^1.0|^2.0",
"mockery/mockery": "^1.4",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
"phpmd/phpmd": "^2.11",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1",
"phpunit/phpunit": "^9.5",
"sebastian/phpcpd": "^6.0"
"phpstan/phpstan-strict-rules": "^1.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-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="Blameable Test Suite">
<directory suffix="Tests.php">./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
7 changes: 3 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

![CI](https://github.com/richan-fongdasen/eloquent-blameable/workflows/CI/badge.svg?branch=master)
[![CI](https://github.com/richan-fongdasen/eloquent-blameable/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/richan-fongdasen/eloquent-blameable/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/richan-fongdasen/eloquent-blameable/branch/master/graph/badge.svg)](https://codecov.io/gh/richan-fongdasen/eloquent-blameable)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/richan-fongdasen/eloquent-blameable/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/richan-fongdasen/eloquent-blameable/?branch=master)
[![Total Downloads](https://poser.pugx.org/richan-fongdasen/eloquent-blameable/d/total.svg)](https://packagist.org/packages/richan-fongdasen/eloquent-blameable)
[![Latest Stable Version](https://poser.pugx.org/richan-fongdasen/eloquent-blameable/v/stable.svg)](https://packagist.org/packages/richan-fongdasen/eloquent-blameable)
[![License: MIT](https://poser.pugx.org/laravel/framework/license.svg)](https://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -32,7 +30,7 @@ $ composer require richan-fongdasen/eloquent-blameable
### Laravel version compatibility

| Laravel version | Blameable version |
|:----------------|:------------------|
| :-------------- | :---------------- |
| 5.1.x | 1.0.x |
| 5.2.x - 5.4.x | 1.1.x - 1.2.x |
| 5.5.x - 5.8.x | 1.3.x |
Expand All @@ -41,6 +39,7 @@ $ composer require richan-fongdasen/eloquent-blameable
| 8.x | 1.6.x |
| 9.x | 1.8.x |
| 10.x | 1.9.x |
| 10.x | 1.10.x |

> If you are using Laravel version 5.5+ then you can skip registering the service provider in your Laravel application.
Expand Down
13 changes: 7 additions & 6 deletions tests/HelperTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,52 @@

namespace RichanFongdasen\EloquentBlameableTest;

use PHPUnit\Framework\Attributes\Test;
use RichanFongdasen\EloquentBlameableTest\Supports\Models\Article;
use RichanFongdasen\EloquentBlameableTest\Supports\Models\Post;
use RichanFongdasen\EloquentBlameableTest\Supports\Models\PostWithoutAttributes;

class HelperTests extends TestCase
{
/** @test */
#[Test]
public function it_returns_null_as_current_user_identifier()
{
$this->assertNull(blameable_user(new Post));
}

/** @test */
#[Test]
public function it_returns_current_user_identifier_when_calling_as_user()
{
$this->impersonateUser();

$this->assertEquals($this->user->getKey(), blameable_user(new Post));
}

/** @test */
#[Test]
public function it_returns_current_user_identifier_when_calling_as_other_user()
{
$this->impersonateOtherUser();

$this->assertEquals($this->otherUser->getKey(), blameable_user(new Post));
}

/** @test */
#[Test]
public function it_returns_null_as_current_user_identifier_when_current_user_is_other_class()
{
$this->impersonateUser();

$this->assertNull(blameable_user(new PostWithoutAttributes));
}

/** @test */
#[Test]
public function it_returns_current_impersonated_admin_id()
{
$this->impersonateAdmin();

$this->assertEquals($this->admin->getKey(), blameable_user(new Article));
}

/** @test */
#[Test]
public function it_returns_null_as_current_user_for_the_unauthenticated_user()
{
$this->assertNull(blameable_user(new Article));
Expand Down
Loading

0 comments on commit 4f28c32

Please sign in to comment.