From 8e3d210a90f8f0965d420e635d2ab90f48ce5e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 21 Feb 2024 15:19:39 +0100 Subject: [PATCH 1/4] PHPORM-150 Run CI on Laravel 11 --- .github/workflows/build-ci.yml | 13 ++++++++++--- CHANGELOG.md | 1 + composer.json | 14 ++++++-------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 55cf0f773..28f0e2cbc 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -12,6 +12,8 @@ jobs: strategy: matrix: + mode: + - "stable" os: - "ubuntu-latest" mongodb: @@ -27,7 +29,10 @@ jobs: - php: "8.1" mongodb: "5.0" mode: "low-deps" - + # Laravel 11 + - php: "8.3" + mongodb: "7.0" + mode: "dev" steps: - uses: "actions/checkout@v4" @@ -70,8 +75,10 @@ jobs: restore-keys: "${{ matrix.os }}-composer-" - name: "Install dependencies" - run: composer update --no-interaction $([[ "${{ matrix.mode }}" == low-deps ]] && echo ' --prefer-lowest --prefer-stable') - + run: | + composer update --no-interaction \ + $([[ "${{ matrix.mode }}" == low-deps ]] && echo ' --prefer-lowest --prefer-stable') \ + $([[ "${{ matrix.mode }}" == stable ]] && echo ' --prefer-stable') - name: "Run tests" run: "./vendor/bin/phpunit --coverage-clover coverage.xml" env: diff --git a/CHANGELOG.md b/CHANGELOG.md index d2f745851..f25ab8c77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. ## [unreleased] +* Add support for Laravel 11 by @GromNaN in [#2735](https://github.com/mongodb/laravel-mongodb/pull/2735) * Fix `Query\Builder::dump` and `dd` methods to dump the MongoDB query by @GromNaN in [#2727](https://github.com/mongodb/laravel-mongodb/pull/2727) and [#2730](https://github.com/mongodb/laravel-mongodb/pull/2730) ## [4.1.2] diff --git a/composer.json b/composer.json index 22b75f58f..d19c1149a 100644 --- a/composer.json +++ b/composer.json @@ -24,20 +24,21 @@ "require": { "php": "^8.1", "ext-mongodb": "^1.15", - "illuminate/support": "^10.0", - "illuminate/container": "^10.0", - "illuminate/database": "^10.30", - "illuminate/events": "^10.0", + "illuminate/support": "^10.0|^11", + "illuminate/container": "^10.0|^11", + "illuminate/database": "^10.30|^11", + "illuminate/events": "^10.0|^11", "mongodb/mongodb": "^1.15" }, "require-dev": { "phpunit/phpunit": "^10.3", - "orchestra/testbench": "^8.0", + "orchestra/testbench": "^8.0|^9.0", "mockery/mockery": "^1.4.4", "doctrine/coding-standard": "12.0.x-dev", "spatie/laravel-query-builder": "^5.6", "phpstan/phpstan": "^1.10" }, + "minimum-stability": "dev", "replace": { "jenssegers/mongodb": "self.version" }, @@ -66,9 +67,6 @@ "cs:fix": "phpcbf" }, "config": { - "platform": { - "php": "8.1" - }, "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } From 7cc575458c75d829e904f58e2e18135ded0f53b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 21 Feb 2024 17:27:31 +0100 Subject: [PATCH 2/4] Fix inherited param type --- src/Query/Builder.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 98e6640df..4efa76252 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -614,11 +614,7 @@ public function orderBy($column, $direction = 'asc') return $this; } - /** - * @param list{mixed, mixed}|CarbonPeriod $values - * - * @inheritdoc - */ + /** @inheritdoc */ public function whereBetween($column, iterable $values, $boolean = 'and', $not = false) { $type = 'between'; From 1ee611f1504eaceb007bea732807b3d8c7d1e0cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 21 Feb 2024 21:31:31 +0100 Subject: [PATCH 3/4] Duplicate HasAttributes::getStorableEnumValue() to avoid BC break in method signature in Laravel 11 https://github.com/laravel/framework/commit/8647dcf18e6e315e97daea9ed60ef79b420ad327 --- src/Eloquent/Model.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Eloquent/Model.php b/src/Eloquent/Model.php index 80a29e4fa..acf83247d 100644 --- a/src/Eloquent/Model.php +++ b/src/Eloquent/Model.php @@ -4,6 +4,7 @@ namespace MongoDB\Laravel\Eloquent; +use BackedEnum; use Carbon\CarbonInterface; use DateTimeInterface; use Illuminate\Contracts\Queue\QueueableCollection; @@ -22,6 +23,7 @@ use MongoDB\BSON\UTCDateTime; use MongoDB\Laravel\Query\Builder as QueryBuilder; use Stringable; +use ValueError; use function array_key_exists; use function array_keys; @@ -38,10 +40,12 @@ use function is_string; use function ltrim; use function method_exists; +use function sprintf; use function str_contains; use function str_starts_with; use function strcmp; use function uniqid; +use function var_export; abstract class Model extends BaseModel { @@ -704,7 +708,7 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt } if ($this->isEnumCastable($key) && (! $castValue instanceof Arrayable)) { - $castValue = $castValue !== null ? $this->getStorableEnumValue($castValue) : null; + $castValue = $castValue !== null ? $this->getStorableEnumValueFromLaravel11($this->getCasts()[$key], $castValue) : null; } if ($castValue instanceof Arrayable) { @@ -717,6 +721,23 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt return $attributes; } + /** + * Duplicate of {@see HasAttributes::getStorableEnumValue()} for Laravel 11 as the signature of the method has + * changed in a non-backward compatible way. + * + * @todo Remove this method when support for Laravel 10 is dropped. + */ + private function getStorableEnumValueFromLaravel11($expectedEnum, $value) + { + if (! $value instanceof $expectedEnum) { + throw new ValueError(sprintf('Value [%s] is not of the expected enum type [%s].', var_export($value, true), $expectedEnum)); + } + + return $value instanceof BackedEnum + ? $value->value + : $value->name; + } + /** * Is a value a BSON type? * From 6fba23cb4a77d971b3d3d49f1b5023b48833b709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 21 Feb 2024 21:40:19 +0100 Subject: [PATCH 4/4] Fix CI --- .github/workflows/build-ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 28f0e2cbc..0895d7e8a 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -12,8 +12,6 @@ jobs: strategy: matrix: - mode: - - "stable" os: - "ubuntu-latest" mongodb: @@ -77,8 +75,8 @@ jobs: - name: "Install dependencies" run: | composer update --no-interaction \ - $([[ "${{ matrix.mode }}" == low-deps ]] && echo ' --prefer-lowest --prefer-stable') \ - $([[ "${{ matrix.mode }}" == stable ]] && echo ' --prefer-stable') + $([[ "${{ matrix.mode }}" == low-deps ]] && echo ' --prefer-lowest') \ + $([[ "${{ matrix.mode }}" != dev ]] && echo ' --prefer-stable') - name: "Run tests" run: "./vendor/bin/phpunit --coverage-clover coverage.xml" env: