Skip to content

Commit

Permalink
Laravel 12 support, Larastan update
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Mar 3, 2025
1 parent fe46a83 commit 0234341
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 76 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@ on: [ push ]

jobs:
lint_with_php_cs_fixer:
name: Lint code with PHP-CS-Fixer
name: "Lint code with PHP-CS-Fixer"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "Checkout"
uses: actions/checkout@v4

- name: Install dependencies
- name: "Install dependencies"
uses: php-actions/composer@v6
with:
command: install
only_args: -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --ignore-platform-reqs
php_version: 8.3

- name: Run PHP-CS-Fixer
- name: "Run PHP-CS-Fixer"
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --dry-run

lint_with_phpcs:
name: Lint code with PHP CodeSniffer
name: "Lint code with PHP CodeSniffer"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "Checkout"
uses: actions/checkout@v4

- name: Install dependencies
- name: "Install dependencies"
uses: php-actions/composer@v6
with:
command: install
only_args: -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --ignore-platform-reqs
php_version: 8.3

- name: Run PHP CodeSniffer
- name: "Run PHP CodeSniffer"
run: vendor/bin/phpcs --extensions=php
57 changes: 25 additions & 32 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,57 @@ name: Static Analysis
on: [ push ]

jobs:
PHPUnit:
PHPStan:
strategy:
matrix:
include:
# Laravel 10.*
- php: 8.1
laravel: 10.*
composer-flag: '--prefer-stable'
# Laravel 11.*
- php: 8.2
laravel: 10.*
laravel: 11.*
composer-flag: '--prefer-stable'
- php: 8.3
laravel: 10.*
laravel: 11.*
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
- php: 8.4
laravel: 11.*
testbench: 9.*
composer-flag: '--prefer-stable'
# Laravel 12.*
- php: 8.2
laravel: 12.*
composer-flag: '--prefer-stable'
- php: 8.3
laravel: 11.*
testbench: 9.*
laravel: 12.*
composer-flag: '--prefer-stable'
- php: 8.4
laravel: 12.*
composer-flag: '--prefer-stable'
- php: 8.2
laravel: 11.*
testbench: 9.*
laravel: 12.*
composer-flag: '--prefer-lowest'
- php: 8.2
laravel: 11.*
testbench: 9.*
- php: 8.3
laravel: 12.*
composer-flag: '--prefer-lowest'
- php: 8.4
laravel: 12.*
composer-flag: '--prefer-lowest'

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: "Checkout"
uses: actions/checkout@v4

- name: Setup PHP
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: none

- name: Install dependencies
- name: "Install dependencies"
run: composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update

- name: Update dependencies
- name: "Update dependencies"
run: composer update ${{ matrix.composer-flag }} --prefer-dist --no-interaction

- name: Run PhpStan
- name: "Run PhpStan"
run: composer analyse
58 changes: 45 additions & 13 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,93 @@ jobs:
- php: 8.1
laravel: 10.*
composer-flag: '--prefer-stable'
phpunit-config: 'phpunit-10.xml'
- php: 8.2
laravel: 10.*
composer-flag: '--prefer-stable'
phpunit-config: 'phpunit-10.xml'
- php: 8.3
laravel: 10.*
composer-flag: '--prefer-stable'
phpunit-config: 'phpunit-10.xml'
- php: 8.1
laravel: 10.*
composer-flag: '--prefer-lowest'
phpunit-config: 'phpunit-10.xml'
- php: 8.2
laravel: 10.*
composer-flag: '--prefer-lowest'
phpunit-config: 'phpunit-10.xml'
- php: 8.3
laravel: 10.*
composer-flag: '--prefer-lowest'
# Laravel 11.*
phpunit-config: 'phpunit-10.xml'
# Laravel 11.*
- php: 8.2
laravel: 11.*
testbench: 9.*
composer-flag: '--prefer-stable'
phpunit-config: 'phpunit.xml'
- php: 8.3
laravel: 11.*
testbench: 9.*
composer-flag: '--prefer-stable'
phpunit-config: 'phpunit.xml'
- php: 8.4
laravel: 11.*
composer-flag: '--prefer-stable'
phpunit-config: 'phpunit.xml'
- php: 8.2
laravel: 11.*
testbench: 9.*
composer-flag: '--prefer-lowest'
phpunit-config: 'phpunit.xml'
# Laravel 12.*
- php: 8.2
laravel: 11.*
testbench: 9.*
laravel: 12.*
composer-flag: '--prefer-stable'
phpunit-config: 'phpunit.xml'
- php: 8.3
laravel: 12.*
composer-flag: '--prefer-stable'
phpunit-config: 'phpunit.xml'
- php: 8.4
laravel: 12.*
composer-flag: '--prefer-stable'
phpunit-config: 'phpunit.xml'
- php: 8.2
laravel: 12.*
composer-flag: '--prefer-lowest'
phpunit-config: 'phpunit.xml'
- php: 8.3
laravel: 12.*
composer-flag: '--prefer-lowest'
phpunit-config: 'phpunit.xml'
- php: 8.4
laravel: 12.*
composer-flag: '--prefer-lowest'
phpunit-config: 'phpunit.xml'

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: "Checkout"
uses: actions/checkout@v4

- name: Setup PHP
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: xdebug

- name: Install dependencies
- name: "Install dependencies"
run: composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update

- name: Update dependencies
- name: "Update dependencies"
run: composer update ${{ matrix.composer-flag }} --prefer-dist --no-interaction

- name: Run PHPUnit
run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
- name: "Run PHPUnit"
run: XDEBUG_MODE=coverage vendor/bin/phpunit --config="${{ matrix.phpunit-config }}" --coverage-text --coverage-clover=coverage.xml

- name: Upload coverage reports to Codecov
- name: "Upload coverage reports to Codecov"
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
],
"require": {
"php": ">=8.1",
"illuminate/database": "^10|^11"
"illuminate/database": "^10|^11|^12"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^8|^9",
"phpunit/phpunit": "^10",
"nunomaduro/larastan": "^2.0|^3",
"orchestra/testbench": "^8|^9|^10",
"phpunit/phpunit": "^10|^11",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
Expand Down
27 changes: 27 additions & 0 deletions phpunit-10.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Feature">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<server name="APP_ENV" value="testing"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="QUEUE_DRIVER" value="sync"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
12 changes: 6 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Feature">
<directory>tests</directory>
Expand All @@ -24,4 +19,9 @@
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
</php>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ composer require korridor/laravel-has-many-merged "^0"

This package is tested for the following Laravel versions:

- 12.* (PHP 8.2, 8.3, 8.4)
- 11.* (PHP 8.2, 8.3, 8.4)
- 10.* (PHP 8.1, 8.2, 8.3)
- 11.* (PHP 8.2, 8.3)

## Usage examples

Expand Down
3 changes: 2 additions & 1 deletion src/HasManyMerged.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

/**
* @template TRelatedModel of Model
* @extends Relation<TRelatedModel>
* @template TDeclaringModel of Model
* @extends Relation<TRelatedModel, TDeclaringModel, Collection<int, TRelatedModel>>
*/
class HasManyMerged extends Relation
{
Expand Down
4 changes: 0 additions & 4 deletions tests/HasManyMergedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ public function testHasManyMergedWithTwoUsersWereBothAreSenderOrReceiverOfTheSam

public function testHasManyMergedWithTwoUsersWereBothAreSenderOrReceiverOfTheSameFourMessagesWithEagerLoadingWithSum(): void
{
if (! method_exists(Builder::class, 'withSum')) {
$this->markTestSkipped('withSum is not supported');
}

// Arrange
$this->createTwoUsersWereBothAreSenderOrReceiverOfTheSameFourMessages();

Expand Down
6 changes: 3 additions & 3 deletions tests/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Message extends Model
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
* @var list<string>
*/
protected $fillable = [
'id',
Expand All @@ -29,15 +29,15 @@ class Message extends Model
];

/**
* @return BelongsTo<User, Message>
* @return BelongsTo<User, $this>
*/
public function sender(): BelongsTo
{
return $this->belongsTo(User::class, 'sender_user_id');
}

/**
* @return BelongsTo<User, Message>
* @return BelongsTo<User, $this>
*/
public function receiver(): BelongsTo
{
Expand Down
Loading

0 comments on commit 0234341

Please sign in to comment.