Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: "weekly"
interval: weekly
17 changes: 14 additions & 3 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ on:
jobs:
build:
runs-on: ${{ matrix.os }}

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

strategy:
matrix:
os:
Expand All @@ -30,6 +32,7 @@ jobs:

steps:
- 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 @@ -39,40 +42,48 @@ 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
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"

- name: Installing php
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
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- 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
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
run: composer test:coverage
env:
MONGODB_URI: 'mongodb://127.0.0.1/?replicaSet=rs'

- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
34 changes: 17 additions & 17 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ jobs:
runs-on: "ubuntu-22.04"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"
- name: Checkout
uses: actions/checkout@v4

- 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"
extensions: mongodb-${{ env.DRIVER_VERSION }}
key: extcache-v1

- name: Cache extensions
uses: actions/cache@v3
Expand All @@ -34,22 +34,22 @@ jobs:
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: "none"
extensions: "mongodb-${{ env.DRIVER_VERSION }}"
php-version: "${{ env.PHP_VERSION }}"
tools: "cs2pr"
coverage: none
extensions: mongodb-${{ env.DRIVER_VERSION }}
php-version: ${{ env.PHP_VERSION }}
tools: cs2pr

- name: "Show driver information"
run: "php --ri mongodb"
- name: Show driver information
run: php --ri mongodb

- name: "Install dependencies with Composer"
uses: "ramsey/[email protected]"
- name: Install dependencies with Composer
uses: ramsey/[email protected]
with:
composer-options: "--no-suggest"
composer-options: --no-suggest

# The -q option is required until phpcs v4 is released
- name: "Run PHP_CodeSniffer"
run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr"
- name: Run PHP_CodeSniffer
run: vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr
19 changes: 9 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
ARG PHP_VERSION=8.1

FROM php:${PHP_VERSION}-cli
FROM php:8.1-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

ENV COMPOSER_ALLOW_SUPERUSER=1

WORKDIR /code
# Increase memory limit
RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini && \
echo "memory_limit=-1" >> /usr/local/etc/php/php.ini

COPY ./ ./
# Enable coverage mode in xdebug
RUN echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/xdebug.ini
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xdebug mode is set to coverage.


CMD ["bash", "-c", "composer install && ./vendor/bin/phpunit --testdox"]
# Install Composer
RUN curl https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
]
}
},
"scripts": {
"test": "./vendor/bin/phpunit",
"test:group": "./vendor/bin/phpunit --group test",
"test:coverage": "./vendor/bin/phpunit --coverage-clover ./coverage.xml",
"cs": "./vendor/bin/phpcs",
"cs:fix": "./vendor/bin/phpcbf"
},
"config": {
"platform": {
"php": "8.1"
Expand Down
13 changes: 5 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
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
environment:
MONGODB_URI: 'mongodb://mongodb/'
volumes:
- .:/var/www/laravel-mongodb
depends_on:
mongodb:
condition: service_healthy
Expand Down