diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 55cf0f773..0895d7e8a 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -27,7 +27,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 +73,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') \ + $([[ "${{ matrix.mode }}" != dev ]] && 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 } 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? * 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';