Browse Source

Move continuous integration from travis-ci to GitHub Actions (#279)

* Allow configuring MongoDB URI in tests

* Move CI pipeline to GitHub Actions

* Require stable phpunit-bridge version

* Remove travis configuration

* Remove scrutinizer configuration
Andreas Braun 5 years ago
parent
commit
a0c060d93e

+ 63 - 0
.github/workflows/coding-standards.yml

@@ -0,0 +1,63 @@
+name: "Coding Standards"
+
+on:
+  pull_request:
+    branches:
+      - "*.x"
+  push:
+    branches:
+      - "*.x"
+
+jobs:
+  coding-standards:
+    name: "Coding Standards"
+    runs-on: "ubuntu-20.04"
+
+    strategy:
+      matrix:
+        php-version:
+          - "7.2"
+
+    steps:
+      - name: "Checkout"
+        uses: "actions/checkout@v2"
+
+      - name: Setup cache environment
+        id: extcache
+        uses: shivammathur/cache-extensions@v1
+        with:
+          php-version: ${{ matrix.php-version }}
+          extensions: "mongodb"
+          key: "extcache-v1"
+
+      - name: Cache extensions
+        uses: actions/cache@v2
+        with:
+          path: ${{ steps.extcache.outputs.dir }}
+          key: ${{ steps.extcache.outputs.key }}
+          restore-keys: ${{ steps.extcache.outputs.key }}
+
+      - name: "Install PHP"
+        uses: "shivammathur/setup-php@v2"
+        with:
+          coverage: "none"
+          extensions: "mongodb"
+          php-version: "${{ matrix.php-version }}"
+          tools: "cs2pr"
+
+      - name: "Show driver information"
+        run: "php --ri mongodb"
+
+      - name: "Cache dependencies installed with Composer"
+        uses: "actions/cache@v2"
+        with:
+          path: "~/.composer/cache"
+          key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.json') }}"
+          restore-keys: "php-${{ matrix.php-version }}-composer-normal-"
+
+      - name: "Install dependencies with Composer"
+        run: "composer install --no-interaction --no-progress --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"

+ 159 - 0
.github/workflows/tests.yml

@@ -0,0 +1,159 @@
+name: "Tests"
+
+on:
+  pull_request:
+    branches:
+      - "*.x"
+  push:
+    branches:
+      - "*.x"
+
+jobs:
+  verification:
+    name: "Verification tests"
+    runs-on: "ubuntu-16.04"
+
+    steps:
+      - name: "Checkout"
+        uses: "actions/checkout@v2"
+        with:
+          fetch-depth: 2
+
+      - name: Setup cache environment
+        id: extcache
+        uses: shivammathur/cache-extensions@v1
+        with:
+          php-version: "5.6"
+          extensions: "mongodb-1.7.5, mongo-1.6.14"
+          key: "extcache-v1"
+
+      - name: Cache extensions
+        uses: actions/cache@v2
+        with:
+          path: ${{ steps.extcache.outputs.dir }}
+          key: ${{ steps.extcache.outputs.key }}
+          restore-keys: ${{ steps.extcache.outputs.key }}
+
+      - name: "Install PHP"
+        uses: "shivammathur/setup-php@v2"
+        with:
+          php-version: "5.6"
+          tools: "pecl"
+          extensions: "mongodb-1.7.5, mongo-1.6.14"
+          coverage: "none"
+          ini-values: "zend.assertions=1"
+
+      - name: "Show legacy driver information"
+        run: "php --ri mongo"
+
+      - name: "Show driver information"
+        run: "php --ri mongodb"
+
+      - name: "Cache dependencies installed with composer"
+        uses: "actions/cache@v2"
+        with:
+          path: "~/.composer/cache"
+          key: "php-5.6-composer-locked-${{ hashFiles('composer.json') }}"
+          restore-keys: "php-5.6-composer-normal-"
+
+      - name: "Install dependencies with composer"
+        run: "composer update --no-interaction --no-progress"
+
+      - id: setup-mongodb
+        uses: mongodb-labs/drivers-evergreen-tools@master
+        with:
+          version: "3.0"
+
+      - name: "Run PHPUnit"
+        run: "vendor/bin/simple-phpunit -v"
+        env:
+          SYMFONY_DEPRECATIONS_HELPER: 999999
+          MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }}
+
+  phpunit:
+    name: "PHPUnit tests"
+    runs-on: "${{ matrix.os }}"
+
+    strategy:
+      fail-fast: true
+      matrix:
+        os:
+          - "ubuntu-18.04"
+        php-version:
+          - "7.0"
+          - "7.1"
+          - "7.2"
+          - "7.3"
+          - "7.4"
+          - "8.0"
+        mongodb-version:
+          - "4.4"
+        driver-version:
+          - "stable"
+        deps:
+          - "normal"
+        include:
+          - deps: "low"
+            os: "ubuntu-16.04"
+            php-version: "5.6"
+            mongodb-version: "3.0"
+            driver-version: "1.2.0"
+
+    steps:
+      - name: "Checkout"
+        uses: "actions/checkout@v2"
+        with:
+          fetch-depth: 2
+
+      - name: Setup cache environment
+        id: extcache
+        uses: shivammathur/cache-extensions@v1
+        with:
+          php-version: ${{ matrix.php-version }}
+          extensions: "mongodb-${{ matrix.driver-version }}"
+          key: "extcache-v1"
+
+      - name: Cache extensions
+        uses: actions/cache@v2
+        with:
+          path: ${{ steps.extcache.outputs.dir }}
+          key: ${{ steps.extcache.outputs.key }}
+          restore-keys: ${{ steps.extcache.outputs.key }}
+
+      - name: "Install PHP"
+        uses: "shivammathur/setup-php@v2"
+        with:
+          php-version: "${{ matrix.php-version }}"
+          tools: "pecl"
+          extensions: "mongodb-${{ matrix.driver-version }}"
+          coverage: "none"
+          ini-values: "zend.assertions=1"
+
+      - name: "Show driver information"
+        run: "php --ri mongodb"
+
+      - name: "Cache dependencies installed with composer"
+        uses: "actions/cache@v2"
+        with:
+          path: "~/.composer/cache"
+          key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.json') }}"
+          restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.deps }}-"
+
+      - name: "Install dependencies with composer"
+        run: "composer update --no-interaction --no-progress"
+        if: "${{ matrix.deps == 'normal' }}"
+
+      - name: "Install lowest possible dependencies with composer"
+        run: "composer update --no-interaction --no-progress --prefer-dist --prefer-lowest"
+        if: "${{ matrix.deps == 'low' }}"
+
+      - id: setup-mongodb
+        uses: mongodb-labs/drivers-evergreen-tools@master
+        with:
+          version: ${{ matrix.mongodb-version }}
+
+      - name: "Run PHPUnit"
+        run: "vendor/bin/simple-phpunit -v"
+        env:
+          SYMFONY_DEPRECATIONS_HELPER: 999999
+          MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }}

+ 0 - 6
.scrutinizer.yml

@@ -1,6 +0,0 @@
-imports:
-    - php
-
-tools:
-    external_code_coverage:
-        timeout: 1200    # Timeout in seconds.

+ 0 - 76
.travis.yml

@@ -1,76 +0,0 @@
-language: php
-dist: xenial
-
-services:
-  - mongodb
-
-php:
-  - 7.0
-  - 7.1
-  - 7.2
-  - 7.3
-  - 7.4
-
-addons:
-  apt:
-    sources:
-      - sourceline: "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse"
-        key_url: "https://www.mongodb.org/static/pgp/server-3.4.asc"
-      - "mongodb-upstart"
-    packages: ['mongodb-org-server']
-
-install:
-  - .travis/install-extension.sh
-  - composer update ${COMPOSER_FLAGS}
-
-script:
-  - vendor/bin/simple-phpunit
-
-jobs:
-  include:
-    # Run tests on PHP 8 with the upcoming extension version
-    - stage: test
-      php: 8.0snapshot
-      env: DRIVER_VERSION="1.9.0RC1"
-      before_install:
-        - composer require --ignore-platform-reqs --no-update mongodb/mongodb 1.8.0-RC1
-
-    # Run tests with coverage
-    - stage: test
-      php: 7.3
-      script:
-        - vendor/bin/simple-phpunit --coverage-clover=coverage.clover
-      after_script:
-        - wget https://scrutinizer-ci.com/ocular.phar
-        - php ocular.phar code-coverage:upload --format=php-clover coverage.clover
-
-    # Test against legacy driver to ensure validity of the test suite
-    - stage: Test
-      dist: trusty
-      php: 5.6
-      env: DRIVER_VERSION="1.7.5" SYMFONY_DEPRECATIONS_HELPER=9999999
-      before_install:
-        - yes '' | pecl -q install -f mongo
-
-    # Test against set of lowest dependencies
-    - stage: Test
-      dist: trusty
-      php: 5.6
-      env: DRIVER_VERSION="1.2.0" COMPOSER_FLAGS="--prefer-dist --prefer-lowest"
-      addons:
-        apt:
-          sources:
-            - sourceline: "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse"
-              key_url: "https://www.mongodb.org/static/pgp/server-3.0.asc"
-            - "mongodb-upstart"
-          packages: ['mongodb-org-server']
-
-    - stage: Code Quality
-      env: CODING_STANDARDS
-      php: 7.2
-      script:
-        - ./vendor/bin/phpcs
-
-cache:
-  directories:
-    - $HOME/.composer/cache

+ 0 - 32
.travis/install-extension.sh

@@ -1,32 +0,0 @@
-#!/bin/sh
-
-# This file was copied from the MongoDB library at https://github.com/mongodb/mongo-php-library.
-# Copyright is (c) MongoDB, Inc.
-
-INI=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
-
-if [ "x${DRIVER_BRANCH}" != "x" ] || [ "x${DRIVER_REPO}" != "x" ]; then
-  CLONE_REPO=${DRIVER_REPO:-https://github.com/mongodb/mongo-php-driver}
-  CHECKOUT_BRANCH=${DRIVER_BRANCH:-master}
-
-  echo "Compiling driver branch ${CHECKOUT_BRANCH} from repository ${CLONE_REPO}"
-
-  mkdir -p /tmp/compile
-  git clone ${CLONE_REPO} /tmp/compile/mongo-php-driver
-  cd /tmp/compile/mongo-php-driver
-
-  git checkout ${CHECKOUT_BRANCH}
-  git submodule update --init
-  phpize
-  ./configure --enable-mongodb-developer-flags
-  make all -j20 > /dev/null
-  make install
-
-  echo "extension=mongodb.so" >> `php --ini | grep "Scan for additional .ini files in" | sed -e "s|.*:\s*||"`/mongodb.ini
-elif [ "x${DRIVER_VERSION}" != "x" ]; then
-  echo "Installing driver version ${DRIVER_VERSION} from PECL"
-  pecl install -f mongodb-${DRIVER_VERSION}
-else
-  echo "Installing latest driver version from PECL"
-  pecl install -f mongodb
-fi

+ 1 - 1
composer.json

@@ -16,7 +16,7 @@
         "mongodb/mongodb": "^1.0.1"
     },
     "require-dev": {
-        "symfony/phpunit-bridge": "5.x-dev",
+        "symfony/phpunit-bridge": "^4.4.16 || ^5.2",
         "squizlabs/php_codesniffer": "^3.2"
     },
     "provide": {

+ 4 - 0
phpunit.xml.dist

@@ -26,4 +26,8 @@
             <directory suffix=".php">./lib/Alcaeus/MongoDbAdapter</directory>
         </whitelist>
     </filter>
+
+    <php>
+        <const name="MONGODB_URI" value="mongodb://localhost:27017" />
+    </php>
 </phpunit>

+ 2 - 2
tests/Alcaeus/MongoDbAdapter/TestCase.php

@@ -32,7 +32,7 @@ abstract class TestCase extends BaseTestCase
      */
     protected function getCheckClient()
     {
-        return new Client('mongodb://localhost', ['connect' => true]);
+        return new Client(MONGODB_URI, ['connect' => true]);
     }
 
     /**
@@ -48,7 +48,7 @@ abstract class TestCase extends BaseTestCase
      * @param array|null $options
      * @return \MongoClient
      */
-    protected function getClient($options = null, $uri = 'mongodb://localhost')
+    protected function getClient($options = null, $uri = MONGODB_URI)
     {
         $args = [$uri];
         if ($options !== null) {