From a27c387cf1c9291ab99359fda02ad3d9bd7b29c2 Mon Sep 17 00:00:00 2001 From: korridor <26689068+korridor@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:17:59 +0100 Subject: [PATCH] Added laravel 11 and PHP 8.3 support; Fixed github actions --- .github/workflows/lint.yml | 4 ++-- .github/workflows/static-analysis.yml | 23 +++++++++++++++++++++++ .github/workflows/unittests.yml | 27 ++++++++++++++++++++++++++- composer.json | 9 +++++---- docker/Dockerfile | 2 +- license.md | 2 +- readme.md | 3 ++- tests/HasManyMergedTest.php | 7 +++++-- tests/Models/Message.php | 2 +- tests/Models/User.php | 4 +++- 10 files changed, 69 insertions(+), 14 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e3cff75..4975c48 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,7 +14,7 @@ jobs: with: command: install only_args: -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --ignore-platform-reqs - php_version: 8.1 + php_version: 8.3 - name: Run PHP-CS-Fixer run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --dry-run @@ -30,7 +30,7 @@ jobs: with: command: install only_args: -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --ignore-platform-reqs - php_version: 8.1 + php_version: 8.3 - name: Run PHP CodeSniffer run: vendor/bin/phpcs --extensions=php diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 20142e6..df395ca 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -14,12 +14,35 @@ jobs: - php: 8.2 laravel: 10.* composer-flag: '--prefer-stable' + - php: 8.3 + laravel: 10.* + composer-flag: '--prefer-stable' - php: 8.1 laravel: 10.* composer-flag: '--prefer-lowest' - php: 8.2 laravel: 10.* composer-flag: '--prefer-lowest' + - php: 8.3 + laravel: 10.* + composer-flag: '--prefer-lowest' + # Laravel 11.* + - php: 8.2 + laravel: 11.* + testbench: 9.* + composer-flag: '--prefer-stable' + - php: 8.3 + laravel: 11.* + testbench: 9.* + composer-flag: '--prefer-stable' + - php: 8.2 + laravel: 11.* + testbench: 9.* + composer-flag: '--prefer-lowest' + - php: 8.2 + laravel: 11.* + testbench: 9.* + composer-flag: '--prefer-lowest' runs-on: ubuntu-latest diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 318f5b0..10a0ed0 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -14,12 +14,35 @@ jobs: - php: 8.2 laravel: 10.* composer-flag: '--prefer-stable' + - php: 8.3 + laravel: 10.* + composer-flag: '--prefer-stable' - php: 8.1 laravel: 10.* composer-flag: '--prefer-lowest' - php: 8.2 laravel: 10.* composer-flag: '--prefer-lowest' + - php: 8.3 + laravel: 10.* + composer-flag: '--prefer-lowest' + # Laravel 11.* + - php: 8.2 + laravel: 11.* + testbench: 9.* + composer-flag: '--prefer-stable' + - php: 8.3 + laravel: 11.* + testbench: 9.* + composer-flag: '--prefer-stable' + - php: 8.2 + laravel: 11.* + testbench: 9.* + composer-flag: '--prefer-lowest' + - php: 8.2 + laravel: 11.* + testbench: 9.* + composer-flag: '--prefer-lowest' runs-on: ubuntu-latest @@ -43,4 +66,6 @@ jobs: run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/composer.json b/composer.json index 5fcf8cd..939f896 100644 --- a/composer.json +++ b/composer.json @@ -10,15 +10,14 @@ "email": "26689068+korridor@users.noreply.github.com" } ], - "minimum-stability": "stable", "require": { "php": ">=8.1", - "illuminate/database": "^10" + "illuminate/database": "^10|^11" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3", "nunomaduro/larastan": "^2.0", - "orchestra/testbench": "^8.9", + "orchestra/testbench": "^8|^9", "phpunit/phpunit": "^10", "squizlabs/php_codesniffer": "^3.5" }, @@ -43,5 +42,7 @@ }, "config": { "sort-packages": true - } + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/docker/Dockerfile b/docker/Dockerfile index a5d71e1..86e2c84 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.1-cli +FROM php:8.3-cli ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ diff --git a/license.md b/license.md index 8f1350d..4098013 100644 --- a/license.md +++ b/license.md @@ -1,7 +1,7 @@ The MIT License (MIT) ===================== -Copyright © `2021` `korridor` +Copyright © `2024` `korridor` Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/readme.md b/readme.md index ea03623..0a4f192 100644 --- a/readme.md +++ b/readme.md @@ -27,7 +27,8 @@ composer require korridor/laravel-has-many-merged "^0" This package is tested for the following Laravel versions: -- 10.* (PHP 8.1, 8.2) +- 10.* (PHP 8.1, 8.2, 8.3) +- 11.* (PHP 8.2, 8.3) ## Usage examples diff --git a/tests/HasManyMergedTest.php b/tests/HasManyMergedTest.php index dfdc41f..3bc9922 100644 --- a/tests/HasManyMergedTest.php +++ b/tests/HasManyMergedTest.php @@ -61,8 +61,10 @@ public function testHasManyMergedWithTwoUsersWereBothAreSenderOrReceiverOfTheSam // Act $this->db::connection()->enableQueryLog(); - $user1 = User::find(11); - $user2 = User::find(12); + /** @var User|null $user1 */ + $user1 = User::query()->find(11); + /** @var User|null $user2 */ + $user2 = User::query()->find(12); $messagesOfUser1 = $user1->messages; $messagesOfUser2 = $user2->messages; $queries = $this->db::connection()->getQueryLog(); @@ -177,6 +179,7 @@ public function testHasManyMergedWithTwoUsersWereBothAreSenderOrReceiverOfTheSam // Assert $this->assertEquals(1, count($users)); $this->assertEquals(2, $users->first()->other_unique_id); + $this->assertCount(2, $queries); } public function testHasManyMergedWithTwoUsersWereBothAreSenderOrReceiverOfTheSameFourMessagesWithLazyEagerLoading(): void diff --git a/tests/Models/Message.php b/tests/Models/Message.php index 92b26d7..51eb364 100644 --- a/tests/Models/Message.php +++ b/tests/Models/Message.php @@ -18,7 +18,7 @@ class Message extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'id', diff --git a/tests/Models/User.php b/tests/Models/User.php index db41cb8..da534f9 100644 --- a/tests/Models/User.php +++ b/tests/Models/User.php @@ -4,6 +4,7 @@ namespace Korridor\LaravelHasManyMerged\Tests\Models; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Korridor\LaravelHasManyMerged\HasManyMerged; @@ -15,6 +16,7 @@ * @property string $name * @property int $messages_sum_content_integer * @property int $messages_count + * @property-read Collection $messages */ class User extends Model { @@ -30,7 +32,7 @@ class User extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'id',