Skip to content

Commit 929f284

Browse files
authored
Fix tests for MongoDB 7.0 (#2579)
Error message have changed Caused by :: Write conflict during plan execution and yielding is disabled. :: Please retry your operation or multi-document transaction.
1 parent f330412 commit 929f284

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

.github/workflows/build-ci.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ jobs:
3636
os:
3737
- ubuntu-latest
3838
mongodb:
39-
- '4.0'
40-
- '4.2'
4139
- '4.4'
4240
- '5.0'
41+
- '6.0'
42+
- '7.0'
4343
php:
4444
- '8.1'
4545
- '8.2'
4646
services:
4747
mysql:
48-
image: mysql:5.7
48+
image: mysql:8.0
4949
ports:
5050
- 3307:3306
5151
env:
@@ -58,13 +58,16 @@ jobs:
5858
- name: Create MongoDB Replica Set
5959
run: |
6060
docker run --name mongodb -p 27017:27017 -e MONGO_INITDB_DATABASE=unittest --detach mongo:${{ matrix.mongodb }} mongod --replSet rs --setParameter transactionLifetimeLimitSeconds=5
61-
until docker exec --tty mongodb mongo 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do
61+
62+
if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
63+
until docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do
6264
sleep 1
6365
done
64-
sudo docker exec --tty mongodb mongo 127.0.0.1:27017 --eval "rs.initiate({\"_id\":\"rs\",\"members\":[{\"_id\":0,\"host\":\"127.0.0.1:27017\" }]})"
66+
sudo docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "rs.initiate({\"_id\":\"rs\",\"members\":[{\"_id\":0,\"host\":\"127.0.0.1:27017\" }]})"
6567
- name: Show MongoDB server status
6668
run: |
67-
docker exec --tty mongodb mongo 127.0.0.1:27017 --eval "db.runCommand({ serverStatus: 1 })"
69+
if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
70+
docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "db.runCommand({ serverStatus: 1 })"
6871
- name: "Installing php"
6972
uses: shivammathur/setup-php@v2
7073
with:

Dockerfile

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
ARG PHP_VERSION=8.1
2-
ARG COMPOSER_VERSION=2.5.4
32

43
FROM php:${PHP_VERSION}-cli
54

65
RUN apt-get update && \
7-
apt-get install -y autoconf pkg-config libssl-dev git libzip-dev zlib1g-dev && \
6+
apt-get install -y autoconf pkg-config libssl-dev git unzip libzip-dev zlib1g-dev && \
87
pecl install mongodb && docker-php-ext-enable mongodb && \
98
pecl install xdebug && docker-php-ext-enable xdebug && \
109
docker-php-ext-install -j$(nproc) pdo_mysql zip
1110

12-
COPY --from=composer:${COMPOSER_VERSION} /usr/bin/composer /usr/local/bin/composer
11+
COPY --from=composer:2.5.8 /usr/bin/composer /usr/local/bin/composer
1312

1413
WORKDIR /code
1514

16-
COPY composer.* ./
17-
18-
RUN composer install
19-
2015
COPY ./ ./
2116

17+
ENV COMPOSER_ALLOW_SUPERUSER=1
18+
2219
RUN composer install
2320

24-
CMD ["./vendor/bin/phpunit"]
21+
CMD ["./vendor/bin/phpunit", "--testdox"]

docker-compose.yml

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3'
1+
version: '3.5'
22

33
services:
44
tests:
@@ -10,9 +10,14 @@ services:
1010
volumes:
1111
- .:/code
1212
working_dir: /code
13+
environment:
14+
MONGODB_URI: 'mongodb://mongodb/'
15+
MYSQL_HOST: 'mysql'
1316
depends_on:
14-
- mongodb
15-
- mysql
17+
mongodb:
18+
condition: service_healthy
19+
mysql:
20+
condition: service_started
1621

1722
mysql:
1823
container_name: mysql
@@ -29,3 +34,8 @@ services:
2934
image: mongo:latest
3035
ports:
3136
- "27017:27017"
37+
healthcheck:
38+
test: echo 'db.runCommand("ping").ok' | mongosh mongodb:27017 --quiet
39+
interval: 10s
40+
timeout: 10s
41+
retries: 5

tests/TransactionTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ public function testTransactionRespectsRepetitionLimit(): void
384384
$this->fail('Expected exception during transaction');
385385
} catch (BulkWriteException $e) {
386386
$this->assertInstanceOf(BulkWriteException::class, $e);
387-
$this->assertStringContainsString('WriteConflict', $e->getMessage());
388387
}
389388

390389
$this->assertSame(2, $timesRun);

0 commit comments

Comments
 (0)