Skip to content

Commit fc1f9cc

Browse files
hans-thomasTreggatsGromNaN
authored
Update docker and test configs (#2678)
Co-authored-by: Tonko Mulder <[email protected]> Co-authored-by: Jérôme Tamarelle <[email protected]>
1 parent 4d65ca7 commit fc1f9cc

File tree

7 files changed

+78
-66
lines changed

7 files changed

+78
-66
lines changed

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

+47-36
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
name: CI
1+
name: "CI"
22

33
on:
44
push:
55
pull_request:
66

77
jobs:
88
build:
9-
runs-on: ${{ matrix.os }}
10-
name: PHP v${{ matrix.php }} with MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}
9+
runs-on: "${{ matrix.os }}"
10+
11+
name: "PHP v${{ matrix.php }} with MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}"
12+
1113
strategy:
1214
matrix:
1315
os:
14-
- ubuntu-latest
16+
- "ubuntu-latest"
1517
mongodb:
16-
- '4.4'
17-
- '5.0'
18-
- '6.0'
19-
- '7.0'
18+
- "4.4"
19+
- "5.0"
20+
- "6.0"
21+
- "7.0"
2022
php:
21-
- '8.1'
22-
- '8.2'
23-
- '8.3'
23+
- "8.1"
24+
- "8.2"
25+
- "8.3"
2426
include:
25-
- php: '8.1'
26-
mongodb: '5.0'
27-
mode: 'low-deps'
27+
- php: "8.1"
28+
mongodb: "5.0"
29+
mode: "low-deps"
2830

2931
steps:
30-
- uses: actions/checkout@v4
31-
- name: Create MongoDB Replica Set
32+
- uses: "actions/checkout@v4"
33+
34+
- name: "Create MongoDB Replica Set"
3235
run: |
3336
docker run --name mongodb -p 27017:27017 -e MONGO_INITDB_DATABASE=unittest --detach mongo:${{ matrix.mongodb }} mongod --replSet rs --setParameter transactionLifetimeLimitSeconds=5
3437
@@ -37,35 +40,43 @@ jobs:
3740
sleep 1
3841
done
3942
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\" }]})"
40-
- name: Show MongoDB server status
43+
44+
- name: "Show MongoDB server status"
4145
run: |
4246
if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
4347
docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "db.runCommand({ serverStatus: 1 })"
48+
4449
- name: "Installing php"
45-
uses: shivammathur/setup-php@v2
50+
uses: "shivammathur/setup-php@v2"
4651
with:
4752
php-version: ${{ matrix.php }}
48-
extensions: curl,mbstring,xdebug
49-
coverage: xdebug
50-
tools: composer
51-
- name: Show PHP version
52-
run: php -v && composer -V
53-
- name: Show Docker version
54-
run: if [[ "$DEBUG" == "true" ]]; then docker version && env; fi
55-
env:
56-
DEBUG: ${{ secrets.DEBUG }}
57-
- name: Download Composer cache dependencies from cache
58-
id: composer-cache
53+
extensions: "curl,mbstring,xdebug"
54+
coverage: "xdebug"
55+
tools: "composer"
56+
57+
- name: "Show PHP version"
58+
if: ${{ secrets.DEBUG == 'true' }}
59+
run: "php -v && composer -V"
60+
61+
- name: "Show Docker version"
62+
if: ${{ secrets.DEBUG == 'true' }}
63+
run: "docker version && env"
64+
65+
- name: "Download Composer cache dependencies from cache"
66+
id: "composer-cache"
5967
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
60-
- name: Cache Composer dependencies
61-
uses: actions/cache@v3
68+
69+
- name: "Cache Composer dependencies"
70+
uses: "actions/cache@v3"
6271
with:
6372
path: ${{ steps.composer-cache.outputs.dir }}
64-
key: ${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}
65-
restore-keys: ${{ matrix.os }}-composer-
66-
- name: Install dependencies
73+
key: "${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}"
74+
restore-keys: "${{ matrix.os }}-composer-"
75+
76+
- name: "Install dependencies"
6777
run: composer update --no-interaction $([[ "${{ matrix.mode }}" == low-deps ]] && echo ' --prefer-lowest --prefer-stable')
68-
- name: Run tests
69-
run: ./vendor/bin/phpunit --coverage-clover coverage.xml
78+
79+
- name: "Run tests"
80+
run: "./vendor/bin/phpunit --coverage-clover coverage.xml"
7081
env:
7182
MONGODB_URI: 'mongodb://127.0.0.1/?replicaSet=rs'

Diff for: .github/workflows/coding-standards.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ jobs:
2222
- name: "Checkout"
2323
uses: "actions/checkout@v4"
2424

25-
- name: Setup cache environment
26-
id: extcache
27-
uses: shivammathur/cache-extensions@v1
25+
- name: "Setup cache environment"
26+
id: "extcache"
27+
uses: "shivammathur/cache-extensions@v1"
2828
with:
2929
php-version: ${{ env.PHP_VERSION }}
3030
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
3131
key: "extcache-v1"
3232

33-
- name: Cache extensions
34-
uses: actions/cache@v3
33+
- name: "Cache extensions"
34+
uses: "actions/cache@v3"
3535
with:
3636
path: ${{ steps.extcache.outputs.dir }}
3737
key: ${{ steps.extcache.outputs.key }}
@@ -42,7 +42,7 @@ jobs:
4242
with:
4343
coverage: "none"
4444
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
45-
php-version: "${{ env.PHP_VERSION }}"
45+
php-version: ${{ env.PHP_VERSION }}
4646
tools: "cs2pr"
4747

4848
- name: "Show driver information"

Diff for: CONTRIBUTING.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,27 @@ Before submitting a pull request:
3838

3939
## Run Tests
4040

41-
The full test suite requires PHP cli with mongodb extension, a running MongoDB server and a running MySQL server.
41+
The full test suite requires PHP cli with mongodb extension, a running MongoDB server.
4242
Duplicate the `phpunit.xml.dist` file to `phpunit.xml` and edit the environment variables to match your setup.
4343

4444
```bash
45-
$ docker-compose up -d mongodb
46-
$ docker-compose run tests
45+
$ docker-compose run app
4746
```
4847

49-
Docker can be slow to start. You can run the command `php vendor/bin/phpunit --testdox` locally or in a docker container.
48+
Docker can be slow to start. You can run the command `composer run test` locally or in a docker container.
5049

5150
```bash
5251
$ docker-compose run -it tests bash
5352
# Inside the container
5453
$ composer install
55-
$ vendor/bin/phpunit --testdox
54+
$ composer run test
5655
```
5756

58-
For fixing style issues, you can run the PHP Code Beautifier and Fixer:
57+
For fixing style issues, you can run the PHP Code Beautifier and Fixer, some issues can't be fixed automatically:
5958

6059
```bash
61-
$ php vendor/bin/phpcbf
60+
$ composer run cs:fix
61+
$ composer run cs
6262
```
6363

6464
## Requirements

Diff for: Dockerfile

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ ARG PHP_VERSION=8.1
22

33
FROM php:${PHP_VERSION}-cli
44

5+
# Install extensions
56
RUN apt-get update && \
67
apt-get install -y autoconf pkg-config libssl-dev git unzip libzip-dev zlib1g-dev && \
78
pecl install mongodb && docker-php-ext-enable mongodb && \
89
pecl install xdebug && docker-php-ext-enable xdebug && \
910
docker-php-ext-install -j$(nproc) zip
1011

11-
COPY --from=composer:2.6.2 /usr/bin/composer /usr/local/bin/composer
12+
# Create php.ini
13+
RUN cp "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
1214

13-
ENV COMPOSER_ALLOW_SUPERUSER=1
14-
15-
WORKDIR /code
16-
17-
COPY ./ ./
18-
19-
CMD ["bash", "-c", "composer install && ./vendor/bin/phpunit --testdox"]
15+
# Install Composer
16+
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer

Diff for: composer.json

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
]
6060
}
6161
},
62+
"scripts": {
63+
"test": "phpunit",
64+
"test:coverage": "phpunit --coverage-clover ./coverage.xml",
65+
"cs": "phpcs",
66+
"cs:fix": "phpcbf"
67+
},
6268
"config": {
6369
"platform": {
6470
"php": "8.1"

Diff for: docker-compose.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
version: '3.5'
22

33
services:
4-
tests:
5-
container_name: tests
4+
app:
65
tty: true
7-
build:
8-
context: .
9-
dockerfile: Dockerfile
10-
volumes:
11-
- .:/code
12-
working_dir: /code
6+
build: .
7+
working_dir: /var/www/laravel-mongodb
8+
command: "bash -c 'composer install && composer run test'"
139
environment:
1410
MONGODB_URI: 'mongodb://mongodb/'
11+
volumes:
12+
- .:/var/www/laravel-mongodb
1513
depends_on:
1614
mongodb:
1715
condition: service_healthy

Diff for: phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<env name="MONGODB_DATABASE" value="unittest"/>
1919
<env name="SQLITE_DATABASE" value=":memory:"/>
2020
<env name="QUEUE_CONNECTION" value="database"/>
21-
21+
<ini name="xdebug.mode" value="coverage"/>
2222
<ini name="memory_limit" value="-1"/>
2323
</php>
2424

0 commit comments

Comments
 (0)