Skip to content

Commit 9b72148

Browse files
authored
PHPORM-150 Run CI on Laravel 11 (#2735)
* Run CI on Laravel 11 * Fix inherited param type * Duplicate HasAttributes::getStorableEnumValue() to avoid BC break in method signature in Laravel 11 laravel/framework@8647dcf
1 parent decbd99 commit 9b72148

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

Diff for: .github/workflows/build-ci.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ jobs:
2727
- php: "8.1"
2828
mongodb: "5.0"
2929
mode: "low-deps"
30-
30+
# Laravel 11
31+
- php: "8.3"
32+
mongodb: "7.0"
33+
mode: "dev"
3134
steps:
3235
- uses: "actions/checkout@v4"
3336

@@ -70,8 +73,10 @@ jobs:
7073
restore-keys: "${{ matrix.os }}-composer-"
7174

7275
- name: "Install dependencies"
73-
run: composer update --no-interaction $([[ "${{ matrix.mode }}" == low-deps ]] && echo ' --prefer-lowest --prefer-stable')
74-
76+
run: |
77+
composer update --no-interaction \
78+
$([[ "${{ matrix.mode }}" == low-deps ]] && echo ' --prefer-lowest') \
79+
$([[ "${{ matrix.mode }}" != dev ]] && echo ' --prefer-stable')
7580
- name: "Run tests"
7681
run: "./vendor/bin/phpunit --coverage-clover coverage.xml"
7782
env:

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
33

44
## [unreleased]
55

6+
* Add support for Laravel 11 by @GromNaN in [#2735](https://github.com/mongodb/laravel-mongodb/pull/2735)
67
* 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)
78

89
## [4.1.2]

Diff for: composer.json

+6-8
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,21 @@
2424
"require": {
2525
"php": "^8.1",
2626
"ext-mongodb": "^1.15",
27-
"illuminate/support": "^10.0",
28-
"illuminate/container": "^10.0",
29-
"illuminate/database": "^10.30",
30-
"illuminate/events": "^10.0",
27+
"illuminate/support": "^10.0|^11",
28+
"illuminate/container": "^10.0|^11",
29+
"illuminate/database": "^10.30|^11",
30+
"illuminate/events": "^10.0|^11",
3131
"mongodb/mongodb": "^1.15"
3232
},
3333
"require-dev": {
3434
"phpunit/phpunit": "^10.3",
35-
"orchestra/testbench": "^8.0",
35+
"orchestra/testbench": "^8.0|^9.0",
3636
"mockery/mockery": "^1.4.4",
3737
"doctrine/coding-standard": "12.0.x-dev",
3838
"spatie/laravel-query-builder": "^5.6",
3939
"phpstan/phpstan": "^1.10"
4040
},
41+
"minimum-stability": "dev",
4142
"replace": {
4243
"jenssegers/mongodb": "self.version"
4344
},
@@ -66,9 +67,6 @@
6667
"cs:fix": "phpcbf"
6768
},
6869
"config": {
69-
"platform": {
70-
"php": "8.1"
71-
},
7270
"allow-plugins": {
7371
"dealerdirect/phpcodesniffer-composer-installer": true
7472
}

Diff for: src/Eloquent/Model.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace MongoDB\Laravel\Eloquent;
66

7+
use BackedEnum;
78
use Carbon\CarbonInterface;
89
use DateTimeInterface;
910
use Illuminate\Contracts\Queue\QueueableCollection;
@@ -22,6 +23,7 @@
2223
use MongoDB\BSON\UTCDateTime;
2324
use MongoDB\Laravel\Query\Builder as QueryBuilder;
2425
use Stringable;
26+
use ValueError;
2527

2628
use function array_key_exists;
2729
use function array_keys;
@@ -38,10 +40,12 @@
3840
use function is_string;
3941
use function ltrim;
4042
use function method_exists;
43+
use function sprintf;
4144
use function str_contains;
4245
use function str_starts_with;
4346
use function strcmp;
4447
use function uniqid;
48+
use function var_export;
4549

4650
abstract class Model extends BaseModel
4751
{
@@ -704,7 +708,7 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt
704708
}
705709

706710
if ($this->isEnumCastable($key) && (! $castValue instanceof Arrayable)) {
707-
$castValue = $castValue !== null ? $this->getStorableEnumValue($castValue) : null;
711+
$castValue = $castValue !== null ? $this->getStorableEnumValueFromLaravel11($this->getCasts()[$key], $castValue) : null;
708712
}
709713

710714
if ($castValue instanceof Arrayable) {
@@ -717,6 +721,23 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt
717721
return $attributes;
718722
}
719723

724+
/**
725+
* Duplicate of {@see HasAttributes::getStorableEnumValue()} for Laravel 11 as the signature of the method has
726+
* changed in a non-backward compatible way.
727+
*
728+
* @todo Remove this method when support for Laravel 10 is dropped.
729+
*/
730+
private function getStorableEnumValueFromLaravel11($expectedEnum, $value)
731+
{
732+
if (! $value instanceof $expectedEnum) {
733+
throw new ValueError(sprintf('Value [%s] is not of the expected enum type [%s].', var_export($value, true), $expectedEnum));
734+
}
735+
736+
return $value instanceof BackedEnum
737+
? $value->value
738+
: $value->name;
739+
}
740+
720741
/**
721742
* Is a value a BSON type?
722743
*

Diff for: src/Query/Builder.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -614,11 +614,7 @@ public function orderBy($column, $direction = 'asc')
614614
return $this;
615615
}
616616

617-
/**
618-
* @param list{mixed, mixed}|CarbonPeriod $values
619-
*
620-
* @inheritdoc
621-
*/
617+
/** @inheritdoc */
622618
public function whereBetween($column, iterable $values, $boolean = 'and', $not = false)
623619
{
624620
$type = 'between';

0 commit comments

Comments
 (0)