From c9e845afa09df9244b50359afb1bc01601d81068 Mon Sep 17 00:00:00 2001 From: Sebastiaan Luca Date: Sun, 25 Feb 2024 01:38:13 +0100 Subject: [PATCH] Add support for PHP 8.3 and Laravel 11 (#2) --- .github/dependabot.yml | 8 +++++ .github/workflows/test.yml | 40 ++++++++------------- .php-cs-fixer.dist.php | 5 +++ CHANGELOG.md | 11 ++++++ README.md | 2 +- composer.json | 52 ++++++++++++++++++--------- phpunit.xml.dist | 35 ++++++------------ pint.json | 12 +++++++ rector.php | 61 +++++++++++++++++++++++++++++++ tests/BooleanAttributeTest.php | 65 +++++++++------------------------- 10 files changed, 175 insertions(+), 116 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 pint.json create mode 100644 rector.php diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..162da22 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + target-branch: "develop" + schedule: + interval: "monthly" + open-pull-requests-limit: 5 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5467742..38e279e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,38 +1,24 @@ -name: Check code +name: Run tests on: push: pull_request: jobs: - - check: - name: Run checks - PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} + test: + name: Run tests - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: - fail-fast: false + fail-fast: true matrix: - php: [8.1, 8.2] - dependency-version: [prefer-lowest, prefer-stable] - os: [ubuntu-latest] + os: [ ubuntu-latest ] + php: [ 8.2, 8.3 ] + laravel: [ 10.*, 11.* ] + stability: [ prefer-lowest, prefer-stable ] steps: - - name: Check out code - uses: actions/checkout@v2 - - - name: Cache PHP dependencies - uses: actions/cache@v2 - with: - path: '**/vendor' - key: ${{ runner.os }}-vendor-cache-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-vendor-cache- - - - name: Cache Composer dependencies - uses: actions/cache@v2 - with: - path: ~/.composer/cache/files - key: composer-${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('composer.json') }} + - name: Checkout code + uses: actions/checkout@v4 - name: Validate Composer configuration file run: composer validate --strict @@ -45,10 +31,12 @@ jobs: coverage: none - name: Install dependencies - run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress --optimize-autoloader + run: | + composer require "illuminate/database:${{ matrix.laravel }}" "illuminate/support:${{ matrix.laravel }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Lint code - run: PHP_CS_FIXER_IGNORE_ENV=true vendor/bin/php-cs-fixer fix --dry-run --diff + run: vendor/bin/pint --test - name: Run tests run: vendor/bin/phpunit diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 8db5cb0..70d0ba3 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -214,6 +214,11 @@ 'ordered_imports' => [ 'sort_algorithm' => 'alpha', ], + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => true, + 'import_functions' => true, + ], 'no_unneeded_control_parentheses' => [ 'statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'], ], diff --git a/CHANGELOG.md b/CHANGELOG.md index a71643e..2bf6038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All Notable changes to `sebastiaanluca/laravel-boolean-dates` will be documented Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## 8.0.0 (2024-02-25) + +### Added + +- Added support for PHP 8.3 +- Added support for Laravel 11 + +### Removed + +- Dropped support for PHP 8.1 + ## 7.0.1 (2023-02-06) ## 7.0.0 (2023-02-06) diff --git a/README.md b/README.md index aab089f..a91a443 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ composer require sebastiaanluca/laravel-boolean-dates **Set up your Eloquent model** by: -1. Adding your datetime columns to `$casts` +1. Adding your datetime columns to the `$casts` property or `casts()` method 2. Adding the boolean attributes to `$appends` 3. Creating attribute accessors and mutators for each field diff --git a/composer.json b/composer.json index ce99043..3852d54 100644 --- a/composer.json +++ b/composer.json @@ -25,13 +25,16 @@ } ], "require": { - "php": "~8.1|~8.2", - "illuminate/database": "^10.0", - "illuminate/support": "^10.0" + "php": "~8.2|~8.3", + "illuminate/database": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.14", - "phpunit/phpunit": "^9.6" + "friendsofphp/php-cs-fixer": "^3.50", + "laravel/pint": "^1.14", + "phpunit/phpunit": "^11.0.3", + "rector/rector": "^1.0.1", + "roave/security-advisories": "dev-latest" }, "autoload": { "psr-4": { @@ -44,27 +47,42 @@ } }, "config": { + "optimize-autoloader": true, + "preferred-install": "dist", "sort-packages": true }, "minimum-stability": "dev", "prefer-stable": true, "scripts": { - "composer:validate": "@composer validate --strict --ansi", - "test": "vendor/bin/phpunit", - "lint": "PHP_CS_FIXER_IGNORE_ENV=true vendor/bin/php-cs-fixer fix --dry-run --diff --ansi", - "fix": "PHP_CS_FIXER_IGNORE_ENV=true vendor/bin/php-cs-fixer fix --ansi", - "check": [ - "@composer:validate", - "@lint", - "@test" + "post-update-cmd": [ + "@fix" + ], + + "validate:composer": "@composer validate --strict --ansi", + "pint:check": "@php vendor/bin/pint --test --ansi", + "pint": "@php vendor/bin/pint --ansi", + "rector:check": "@php vendor/bin/rector --dry-run --ansi", + "rector": "@php vendor/bin/rector --ansi", + "phpunit": "@php vendor/bin/phpunit --order-by=random", + + "test": [ + "@validate:composer", + "@pint:check", + "@rector:check", + "@phpunit" + ], + "fix": [ + "@pint", + "@rector" ], - "check:lowest": [ + + "test:lowest": [ "composer update --prefer-lowest --prefer-dist --no-interaction --ansi", - "@check" + "@test" ], - "check:stable": [ + "test:stable": [ "composer update --prefer-stable --prefer-dist --no-interaction --ansi", - "@check" + "@test" ] } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a753534..ecffa3d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,26 +1,13 @@ - - - - src/ - - - - - tests - - + + + + tests + + + + + src/ + + diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..48f419f --- /dev/null +++ b/pint.json @@ -0,0 +1,12 @@ +{ + "preset": "laravel", + "rules": { + "phpdoc_single_line_var_spacing": true, + "phpdoc_align": false, + "class_attributes_separation": { + "elements": { + "method": "one" + } + } + } +} diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..4dd0077 --- /dev/null +++ b/rector.php @@ -0,0 +1,61 @@ +withParallel() + ->withPaths([ + __DIR__.'/src', + __DIR__.'/tests', + ]) + ->withImportNames( + importDocBlockNames: false, + removeUnusedImports: true, + ) + ->withPhpSets() + ->withPreparedSets( + deadCode: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + earlyReturn: true, + strictBooleans: true, + ) + ->withSets([ + PHPUnitSetList::PHPUNIT_80, + PHPUnitSetList::PHPUNIT_90, + PHPUnitSetList::PHPUNIT_100, + ]) + ->withRules([ + BoolvalToTypeCastRector::class, + FloatvalToTypeCastRector::class, + IntvalToTypeCastRector::class, + StrvalToTypeCastRector::class, + ReadOnlyClassRector::class, + ReadOnlyPropertyRector::class, + ]) + ->withSkip([ + ArraySpreadInsteadOfArrayMergeRector::class, + CatchExceptionNameMatchingTypeRector::class, + ChangeAndIfToEarlyReturnRector::class, + ChangeOrIfContinueToMultiContinueRector::class, + ClosureToArrowFunctionRector::class, + FirstClassCallableRector::class, + NewlineAfterStatementRector::class, + ]); diff --git a/tests/BooleanAttributeTest.php b/tests/BooleanAttributeTest.php index 75c253f..7cd9380 100644 --- a/tests/BooleanAttributeTest.php +++ b/tests/BooleanAttributeTest.php @@ -6,12 +6,11 @@ use Carbon\CarbonImmutable; use Illuminate\Support\Carbon; +use PHPUnit\Framework\Attributes\Test; class BooleanAttributeTest extends TestCase { - /** - * @test - */ + #[Test] public function it can handle initial values(): void { $model = new TestModel([ @@ -26,9 +25,7 @@ public function it can handle initial values(): void $this->assertTrue($model->is_subscribed_to_newsletter); } - /** - * @test - */ + #[Test] public function it can handle empty initial values(): void { $model = new TestModel; @@ -37,9 +34,7 @@ public function it can handle empty initial values(): void $this->assertFalse($model->has_accepted_terms); } - /** - * @test - */ + #[Test] public function it can enable a boolean attribute(): void { $model = new TestModel; @@ -55,9 +50,7 @@ public function it can enable a boolean attribute(): void $this->assertTrue($model->has_accepted_terms); } - /** - * @test - */ + #[Test] public function it can disable a boolean attribute(): void { $model = new TestModel; @@ -73,9 +66,7 @@ public function it can disable a boolean attribute(): void $this->assertFalse($model->has_accepted_terms); } - /** - * @test - */ + #[Test] public function it cannot enable a boolean attribute twice and change its date(): void { Carbon::setTestNow('2022-03-13 14:31:00'); @@ -95,9 +86,7 @@ public function it cannot enable a boolean attribute twice and change i $this->assertTrue($model->has_accepted_terms); } - /** - * @test - */ + #[Test] public function it can enable a boolean attribute twice if it was disabled(): void { Carbon::setTestNow('2022-03-13 14:00:00'); @@ -124,9 +113,7 @@ public function it can enable a boolean attribute twice if it was disa $this->assertTrue($model->is_subscribed_to_newsletter); } - /** - * @test - */ + #[Test] public function it can enable a boolean attribute from a boolean(): void { $model = new TestModel; @@ -141,9 +128,7 @@ public function it can enable a boolean attribute from a boolean(): void ); } - /** - * @test - */ + #[Test] public function it can enable a boolean attribute from a string(): void { $model = new TestModel; @@ -156,9 +141,7 @@ public function it can enable a boolean attribute from a string(): void ); } - /** - * @test - */ + #[Test] public function it can enable a boolean attribute from an integer string(): void { $model = new TestModel; @@ -171,9 +154,7 @@ public function it can enable a boolean attribute from an integer strin ); } - /** - * @test - */ + #[Test] public function it can enable a boolean attribute from an integer(): void { $model = new TestModel; @@ -186,9 +167,7 @@ public function it can enable a boolean attribute from an integer(): voi ); } - /** - * @test - */ + #[Test] public function it can disable a boolean attribute from a boolean(): void { $model = new TestModel; @@ -198,9 +177,7 @@ public function it can disable a boolean attribute from a boolean(): voi $this->assertNull($model->accepted_processing_at); } - /** - * @test - */ + #[Test] public function it can disable a boolean attribute from null(): void { $model = new TestModel; @@ -210,9 +187,7 @@ public function it can disable a boolean attribute from null(): void $this->assertNull($model->agreed_to_something_at); } - /** - * @test - */ + #[Test] public function it can disable a boolean attribute from an integer string(): void { $model = new TestModel; @@ -222,9 +197,7 @@ public function it can disable a boolean attribute from an integer stri $this->assertNull($model->accepted_terms_at); } - /** - * @test - */ + #[Test] public function it can disable a boolean attribute from an integer(): void { $model = new TestModel; @@ -234,9 +207,7 @@ public function it can disable a boolean attribute from an integer(): vo $this->assertNull($model->accepted_terms_at); } - /** - * @test - */ + #[Test] public function it can disable a boolean attribute from an empty string(): void { $model = new TestModel; @@ -246,9 +217,7 @@ public function it can disable a boolean attribute from an empty string $this->assertNull($model->accepted_terms_at); } - /** - * @test - */ + #[Test] public function it returns all attributes(): void { Carbon::setTestNow('2018-01-01 10:42:06');