Skip to content

Commit

Permalink
Update docker and test configs (#2678)
Browse files Browse the repository at this point in the history
Co-authored-by: Tonko Mulder <tonko@tonkomulder.nl>
Co-authored-by: Jérôme Tamarelle <jerome@tamarelle.net>
  • Loading branch information
3 people authored Dec 4, 2023
1 parent 4d65ca7 commit fc1f9cc
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 66 deletions.
83 changes: 47 additions & 36 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
name: CI
name: "CI"

on:
push:
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}
name: PHP v${{ matrix.php }} with MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}
runs-on: "${{ matrix.os }}"

name: "PHP v${{ matrix.php }} with MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}"

strategy:
matrix:
os:
- ubuntu-latest
- "ubuntu-latest"
mongodb:
- '4.4'
- '5.0'
- '6.0'
- '7.0'
- "4.4"
- "5.0"
- "6.0"
- "7.0"
php:
- '8.1'
- '8.2'
- '8.3'
- "8.1"
- "8.2"
- "8.3"
include:
- php: '8.1'
mongodb: '5.0'
mode: 'low-deps'
- php: "8.1"
mongodb: "5.0"
mode: "low-deps"

steps:
- uses: actions/checkout@v4
- name: Create MongoDB Replica Set
- uses: "actions/checkout@v4"

- name: "Create MongoDB Replica Set"
run: |
docker run --name mongodb -p 27017:27017 -e MONGO_INITDB_DATABASE=unittest --detach mongo:${{ matrix.mongodb }} mongod --replSet rs --setParameter transactionLifetimeLimitSeconds=5
Expand All @@ -37,35 +40,43 @@ jobs:
sleep 1
done
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\" }]})"
- name: Show MongoDB server status
- name: "Show MongoDB server status"
run: |
if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "db.runCommand({ serverStatus: 1 })"
- name: "Installing php"
uses: shivammathur/setup-php@v2
uses: "shivammathur/setup-php@v2"
with:
php-version: ${{ matrix.php }}
extensions: curl,mbstring,xdebug
coverage: xdebug
tools: composer
- name: Show PHP version
run: php -v && composer -V
- name: Show Docker version
run: if [[ "$DEBUG" == "true" ]]; then docker version && env; fi
env:
DEBUG: ${{ secrets.DEBUG }}
- name: Download Composer cache dependencies from cache
id: composer-cache
extensions: "curl,mbstring,xdebug"
coverage: "xdebug"
tools: "composer"

- name: "Show PHP version"
if: ${{ secrets.DEBUG == 'true' }}
run: "php -v && composer -V"

- name: "Show Docker version"
if: ${{ secrets.DEBUG == 'true' }}
run: "docker version && env"

- name: "Download Composer cache dependencies from cache"
id: "composer-cache"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v3

- name: "Cache Composer dependencies"
uses: "actions/cache@v3"
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ matrix.os }}-composer-
- name: Install dependencies
key: "${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}"
restore-keys: "${{ matrix.os }}-composer-"

- name: "Install dependencies"
run: composer update --no-interaction $([[ "${{ matrix.mode }}" == low-deps ]] && echo ' --prefer-lowest --prefer-stable')
- name: Run tests
run: ./vendor/bin/phpunit --coverage-clover coverage.xml

- name: "Run tests"
run: "./vendor/bin/phpunit --coverage-clover coverage.xml"
env:
MONGODB_URI: 'mongodb://127.0.0.1/?replicaSet=rs'
12 changes: 6 additions & 6 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ jobs:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
- name: "Setup cache environment"
id: "extcache"
uses: "shivammathur/cache-extensions@v1"
with:
php-version: ${{ env.PHP_VERSION }}
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
key: "extcache-v1"

- name: Cache extensions
uses: actions/cache@v3
- name: "Cache extensions"
uses: "actions/cache@v3"
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
Expand All @@ -42,7 +42,7 @@ jobs:
with:
coverage: "none"
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
php-version: "${{ env.PHP_VERSION }}"
php-version: ${{ env.PHP_VERSION }}
tools: "cs2pr"

- name: "Show driver information"
Expand Down
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ Before submitting a pull request:

## Run Tests

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

```bash
$ docker-compose up -d mongodb
$ docker-compose run tests
$ docker-compose run app
```

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

```bash
$ docker-compose run -it tests bash
# Inside the container
$ composer install
$ vendor/bin/phpunit --testdox
$ composer run test
```

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

```bash
$ php vendor/bin/phpcbf
$ composer run cs:fix
$ composer run cs
```

## Requirements
Expand Down
13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ ARG PHP_VERSION=8.1

FROM php:${PHP_VERSION}-cli

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

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

ENV COMPOSER_ALLOW_SUPERUSER=1

WORKDIR /code

COPY ./ ./

CMD ["bash", "-c", "composer install && ./vendor/bin/phpunit --testdox"]
# Install Composer
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
]
}
},
"scripts": {
"test": "phpunit",
"test:coverage": "phpunit --coverage-clover ./coverage.xml",
"cs": "phpcs",
"cs:fix": "phpcbf"
},
"config": {
"platform": {
"php": "8.1"
Expand Down
14 changes: 6 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
version: '3.5'

services:
tests:
container_name: tests
app:
tty: true
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/code
working_dir: /code
build: .
working_dir: /var/www/laravel-mongodb
command: "bash -c 'composer install && composer run test'"
environment:
MONGODB_URI: 'mongodb://mongodb/'
volumes:
- .:/var/www/laravel-mongodb
depends_on:
mongodb:
condition: service_healthy
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<env name="MONGODB_DATABASE" value="unittest"/>
<env name="SQLITE_DATABASE" value=":memory:"/>
<env name="QUEUE_CONNECTION" value="database"/>

<ini name="xdebug.mode" value="coverage"/>
<ini name="memory_limit" value="-1"/>
</php>

Expand Down

0 comments on commit fc1f9cc

Please sign in to comment.