Skip to content

Commit a0636f2

Browse files
committed
Split Atlas tests into a distinct workflow matrix
1 parent 19ed55e commit a0636f2

File tree

4 files changed

+90
-25
lines changed

4 files changed

+90
-25
lines changed

.github/workflows/build-ci-atlas.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: "Atlas CI"
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: "${{ matrix.os }}"
10+
11+
name: "PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }} Atlas"
12+
13+
strategy:
14+
matrix:
15+
os:
16+
- "ubuntu-latest"
17+
mongodb:
18+
- "Atlas"
19+
php:
20+
- "8.2"
21+
- "8.3"
22+
- "8.4"
23+
laravel:
24+
- "11.*"
25+
exclude:
26+
- php: "8.1"
27+
laravel: "11.*"
28+
29+
steps:
30+
- uses: "actions/checkout@v4"
31+
32+
- name: "Create MongoDB Atlas Local"
33+
run: |
34+
docker run --name mongodb -p 27017:27017 --detach mongodb/mongodb-atlas-local:latest
35+
until docker exec --tty mongodb mongosh --eval "db.runCommand({ ping: 1 })"; do
36+
sleep 1
37+
done
38+
until docker exec --tty mongodb mongosh --eval "db.createCollection('connection_test') && db.getCollection('connection_test').createSearchIndex({mappings:{dynamic: true}})"; do
39+
sleep 1
40+
done
41+
42+
- name: "Show MongoDB server status"
43+
run: |
44+
docker exec --tty mongodb mongosh --eval "db.runCommand({ serverStatus: 1 })"
45+
46+
- name: "Installing php"
47+
uses: "shivammathur/setup-php@v2"
48+
with:
49+
php-version: ${{ matrix.php }}
50+
extensions: "curl,mbstring,xdebug"
51+
coverage: "xdebug"
52+
tools: "composer"
53+
54+
- name: "Show Docker version"
55+
if: ${{ runner.debug }}
56+
run: "docker version && env"
57+
58+
- name: "Restrict Laravel version"
59+
run: "composer require --dev --no-update 'laravel/framework:${{ matrix.laravel }}'"
60+
61+
- name: "Download Composer cache dependencies from cache"
62+
id: "composer-cache"
63+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
64+
65+
- name: "Cache Composer dependencies"
66+
uses: "actions/cache@v4"
67+
with:
68+
path: ${{ steps.composer-cache.outputs.dir }}
69+
key: "${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}"
70+
restore-keys: "${{ matrix.os }}-composer-"
71+
72+
- name: "Install dependencies"
73+
run: |
74+
composer update --no-interaction
75+
76+
- name: "Run tests"
77+
run: |
78+
export MONGODB_URI="mongodb://127.0.0.1:27017/?directConnection=true"
79+
./vendor/bin/phpunit --coverage-clover coverage.xml --group atlas-search

.github/workflows/build-ci.yml

+7-25
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ jobs:
1111
name: "PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }} MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}"
1212

1313
strategy:
14-
# Tests with Atlas fail randomly
15-
fail-fast: false
1614
matrix:
1715
os:
1816
- "ubuntu-latest"
@@ -21,11 +19,12 @@ jobs:
2119
- "5.0"
2220
- "6.0"
2321
- "7.0"
24-
- "Atlas"
22+
- "8.0"
2523
php:
2624
- "8.1"
2725
- "8.2"
2826
- "8.3"
27+
- "8.4"
2928
laravel:
3029
- "10.*"
3130
- "11.*"
@@ -38,7 +37,6 @@ jobs:
3837
- php: "8.4"
3938
laravel: "11.*"
4039
mongodb: "7.0"
41-
mode: "ignore-php-req"
4240
os: "ubuntu-latest"
4341
exclude:
4442
- php: "8.1"
@@ -48,31 +46,19 @@ jobs:
4846
- uses: "actions/checkout@v4"
4947

5048
- name: "Create MongoDB Replica Set"
51-
if: ${{ matrix.mongodb != 'Atlas' }}
5249
run: |
5350
docker run --name mongodb -p 27017:27017 -e MONGO_INITDB_DATABASE=unittest --detach mongo:${{ matrix.mongodb }} mongod --replSet rs --setParameter transactionLifetimeLimitSeconds=5
5451
5552
if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
56-
until docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do
57-
sleep 1
58-
done
59-
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\" }]})"
60-
61-
- name: "Create MongoDB Atlas Local"
62-
if: ${{ matrix.mongodb == 'Atlas' }}
63-
run: |
64-
docker run --name mongodb -p 27017:27017 --detach mongodb/mongodb-atlas-local:latest
65-
until docker exec --tty mongodb mongosh 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do
66-
sleep 1
67-
done
68-
until docker exec --tty mongodb mongosh 127.0.0.1:27017 --eval "db.createCollection('connection_test') && db.getCollection('connection_test').createSearchIndex({mappings:{dynamic: true}})"; do
53+
until docker exec --tty mongodb $MONGOSH_BIN --eval "db.runCommand({ ping: 1 })"; do
6954
sleep 1
7055
done
56+
sudo docker exec --tty mongodb $MONGOSH_BIN --eval "rs.initiate({\"_id\":\"rs\",\"members\":[{\"_id\":0,\"host\":\"127.0.0.1:27017\" }]})"
7157
7258
- name: "Show MongoDB server status"
7359
run: |
7460
if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
75-
docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "db.runCommand({ serverStatus: 1 })"
61+
docker exec --tty mongodb $MONGOSH_BIN --eval "db.runCommand({ serverStatus: 1 })"
7662
7763
- name: "Installing php"
7864
uses: "shivammathur/setup-php@v2"
@@ -107,9 +93,5 @@ jobs:
10793
$([[ "${{ matrix.mode }}" == ignore-php-req ]] && echo ' --ignore-platform-req=php+')
10894
- name: "Run tests"
10995
run: |
110-
if [ "${{ matrix.mongodb }}" = "Atlas" ]; then
111-
export MONGODB_URI="mongodb://127.0.0.1:27017/"
112-
else
113-
export MONGODB_URI="mongodb://127.0.0.1:27017/?replicaSet=rs"
114-
fi
115-
./vendor/bin/phpunit --coverage-clover coverage.xml
96+
export MONGODB_URI="mongodb://127.0.0.1:27017/?replicaSet=rs"
97+
./vendor/bin/phpunit --coverage-clover coverage.xml --exclude-group atlas-search

tests/AtlasSearchTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use MongoDB\Driver\Exception\ServerException;
1212
use MongoDB\Laravel\Schema\Builder;
1313
use MongoDB\Laravel\Tests\Models\Book;
14+
use PHPUnit\Framework\Attributes\Group;
1415

1516
use function array_map;
1617
use function assert;
@@ -21,6 +22,7 @@
2122
use function usleep;
2223
use function usort;
2324

25+
#[Group('atlas-search')]
2426
class AtlasSearchTest extends TestCase
2527
{
2628
private array $vectors;

tests/Scout/ScoutIntegrationTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use MongoDB\Laravel\Tests\TestCase;
1313
use Override;
1414
use PHPUnit\Framework\Attributes\Depends;
15+
use PHPUnit\Framework\Attributes\Group;
1516

1617
use function array_merge;
1718
use function count;
@@ -21,6 +22,7 @@
2122
use function sprintf;
2223
use function usleep;
2324

25+
#[Group('atlas-search')]
2426
class ScoutIntegrationTest extends TestCase
2527
{
2628
#[Override]

0 commit comments

Comments
 (0)