Skip to content

Commit 3f7cee5

Browse files
committed
PHPORM-306 Test with MongoDB Driver v2
1 parent b91a3c5 commit 3f7cee5

File tree

6 files changed

+162
-119
lines changed

6 files changed

+162
-119
lines changed

.github/workflows/build-ci.yml

+18-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
runs-on: "${{ matrix.os }}"
1010

11-
name: "PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }} MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}"
11+
name: "PHP ${{ matrix.php }} ext ${{ matrix.driver }} Laravel ${{ matrix.laravel }} MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}"
1212

1313
strategy:
1414
matrix:
@@ -29,12 +29,20 @@ jobs:
2929
- "10.*"
3030
- "11.*"
3131
- "12.*"
32+
driver:
33+
- "1.21.0"
3234
include:
3335
- php: "8.1"
3436
laravel: "10.*"
3537
mongodb: "5.0"
3638
mode: "low-deps"
3739
os: "ubuntu-latest"
40+
driver: "1.21.0"
41+
- php: "8.4"
42+
laravel: "12.*"
43+
mongodb: "8.0"
44+
os: "ubuntu-latest"
45+
driver: "mongodb/[email protected]"
3846
exclude:
3947
- php: "8.1"
4048
laravel: "11.*"
@@ -59,11 +67,19 @@ jobs:
5967
if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
6068
docker exec --tty mongodb $MONGOSH_BIN --eval "db.runCommand({ serverStatus: 1 })"
6169
70+
- name: Setup cache environment
71+
id: extcache
72+
uses: shivammathur/cache-extensions@v1
73+
with:
74+
php-version: ${{ matrix.php }}
75+
extensions: "mongodb-${{ matrix.driver }}"
76+
key: "extcache-v1"
77+
6278
- name: "Installing php"
6379
uses: "shivammathur/setup-php@v2"
6480
with:
6581
php-version: ${{ matrix.php }}
66-
extensions: "curl,mbstring,xdebug"
82+
extensions: "curl,mbstring,xdebug,mongodb-${{ matrix.driver }}"
6783
coverage: "xdebug"
6884
tools: "composer"
6985

.github/workflows/static-analysis.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env:
1616

1717
jobs:
1818
phpstan:
19+
name: "PHP ${{ matrix.php }} driver ${{ matrix.driver }}"
1920
runs-on: "ubuntu-22.04"
2021
continue-on-error: true
2122
strategy:
@@ -24,6 +25,12 @@ jobs:
2425
- '8.1'
2526
- '8.2'
2627
- '8.3'
28+
- '8.4'
29+
driver:
30+
- "1.21.0"
31+
include:
32+
- php: '8.4'
33+
driver: 'mongodb/[email protected]'
2734
steps:
2835
- name: Checkout
2936
uses: actions/checkout@v4
@@ -35,11 +42,19 @@ jobs:
3542
run: |
3643
echo CHECKED_OUT_SHA=$(git rev-parse HEAD) >> $GITHUB_ENV
3744
45+
- name: Setup cache environment
46+
id: extcache
47+
uses: shivammathur/cache-extensions@v1
48+
with:
49+
php-version: ${{ matrix.php }}
50+
extensions: "mongodb-${{ matrix.driver }}"
51+
key: "extcache-v1"
52+
3853
- name: Setup PHP
3954
uses: shivammathur/setup-php@v2
4055
with:
4156
php-version: ${{ matrix.php }}
42-
extensions: curl, mbstring
57+
extensions: "curl,mbstring,mongodb-${{ matrix.driver }}"
4358
tools: composer:v2
4459
coverage: none
4560

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
"license": "MIT",
2424
"require": {
2525
"php": "^8.1",
26-
"ext-mongodb": "^1.21",
26+
"ext-mongodb": "^1.21|^2",
2727
"composer-runtime-api": "^2.0.0",
2828
"illuminate/cache": "^10.36|^11|^12",
2929
"illuminate/container": "^10.0|^11|^12",
3030
"illuminate/database": "^10.30|^11|^12",
3131
"illuminate/events": "^10.0|^11|^12",
3232
"illuminate/support": "^10.0|^11|^12",
33-
"mongodb/mongodb": "^1.21",
33+
"mongodb/mongodb": "^1.21|^2",
3434
"symfony/http-foundation": "^6.4|^7"
3535
},
3636
"require-dev": {

src/Eloquent/Builder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use MongoDB\Builder\Type\QueryInterface;
1212
use MongoDB\Builder\Type\SearchOperatorInterface;
1313
use MongoDB\Driver\CursorInterface;
14-
use MongoDB\Driver\Exception\WriteException;
14+
use MongoDB\Driver\Exception\BulkWriteException;
1515
use MongoDB\Laravel\Connection;
1616
use MongoDB\Laravel\Helpers\QueriesRelationships;
1717
use MongoDB\Laravel\Query\AggregationBuilder;
@@ -285,7 +285,7 @@ public function createOrFirst(array $attributes = [], array $values = [])
285285

286286
try {
287287
return $this->create(array_merge($attributes, $values));
288-
} catch (WriteException $e) {
288+
} catch (BulkWriteException $e) {
289289
if ($e->getCode() === self::DUPLICATE_KEY_ERROR) {
290290
return $this->where($attributes)->first() ?? throw $e;
291291
}

tests/QueryBuilderTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function testFindWithTimeout()
161161
$id = DB::table('users')->insertGetId(['name' => 'John Doe']);
162162

163163
$subscriber = new class implements CommandSubscriber {
164-
public function commandStarted(CommandStartedEvent $event)
164+
public function commandStarted(CommandStartedEvent $event): void
165165
{
166166
if ($event->getCommandName() !== 'find') {
167167
return;
@@ -171,11 +171,11 @@ public function commandStarted(CommandStartedEvent $event)
171171
Assert::assertSame(1000, $event->getCommand()->maxTimeMS);
172172
}
173173

174-
public function commandFailed(CommandFailedEvent $event)
174+
public function commandFailed(CommandFailedEvent $event): void
175175
{
176176
}
177177

178-
public function commandSucceeded(CommandSucceededEvent $event)
178+
public function commandSucceeded(CommandSucceededEvent $event): void
179179
{
180180
}
181181
};

0 commit comments

Comments
 (0)