Merge pull request #94 from se7enxweb/copilot/fix-phpp-deprecation-im… #67
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PHPUnit | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| paths: | |
| - '**.php' | |
| - 'composer.json' | |
| - 'composer.lock' | |
| - 'phpunit.xml' | |
| - '.github/workflows/phpunit.yml' | |
| pull_request: | |
| branches: [ main, master ] | |
| paths: | |
| - '**.php' | |
| - 'composer.json' | |
| - 'composer.lock' | |
| - 'phpunit.xml' | |
| - '.github/workflows/phpunit.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| env: | |
| CI_COMPOSER_FILE: composer.ci-phpunit.json | |
| jobs: | |
| phpunit: | |
| name: PHPUnit (PHP ${{ matrix.php }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| php: ['8.1', '8.2', '8.3', '8.4', '8.5'] # matches composer.json support | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| extensions: dom, libxml, mbstring, pcre, json, iconv, reflection, session, spl, simplexml, gd, mongodb, mysqli, pdo_mysql, pdo_sqlite, sqlite3, zip | |
| coverage: xdebug | |
| tools: composer:v2 | |
| - name: Install system packages | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y imagemagick libbson-dev libmongoc-dev | |
| - name: Get Composer cache directory | |
| id: composer-cache | |
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.composer-cache.outputs.dir }} | |
| key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock', 'composer.json', '.github/workflows/phpunit.yml') }} | |
| restore-keys: ${{ runner.os }}-composer- | |
| - name: Install dependencies | |
| run: | | |
| cp composer.json "${CI_COMPOSER_FILE}" | |
| if [[ "${{ matrix.php }}" == "8.1" || "${{ matrix.php }}" == "8.2" || "${{ matrix.php }}" == "8.3" ]]; then | |
| if [[ "${{ matrix.php }}" == "8.1" ]]; then | |
| export PHPUNIT_VERSION="^10.5" | |
| else | |
| export PHPUNIT_VERSION="^11.5" | |
| fi | |
| fi | |
| php -r '$file = getenv("CI_COMPOSER_FILE"); $data = json_decode(file_get_contents($file), true, 512, JSON_THROW_ON_ERROR); if (($phpunit = getenv("PHPUNIT_VERSION")) !== false && $phpunit !== "") { $data["require-dev"]["phpunit/phpunit"] = $phpunit; } $data["require-dev"]["mongodb/mongodb"] = "^1.21 || ^2.0"; file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);' | |
| if [[ -n "${PHPUNIT_VERSION:-}" ]]; then | |
| COMPOSER="${CI_COMPOSER_FILE}" composer update phpunit/phpunit --with-all-dependencies --prefer-dist --no-progress --no-interaction --ignore-platform-req=php --ignore-platform-req=ext-mongodb | |
| else | |
| COMPOSER="${CI_COMPOSER_FILE}" composer install --prefer-dist --no-progress --no-interaction --ignore-platform-req=php --ignore-platform-req=ext-mongodb | |
| fi | |
| - name: Ensure vendor is present | |
| run: | | |
| if [[ ! -x vendor/bin/phpunit ]]; then | |
| echo "vendor/bin/phpunit is missing, reinstalling dependencies" | |
| COMPOSER="${CI_COMPOSER_FILE}" composer install --prefer-dist --no-progress --no-interaction --ignore-platform-req=php --ignore-platform-req=ext-mongodb | |
| fi | |
| test -x vendor/bin/phpunit | |
| # Optional but recommended – regenerates autoloads the same way the project does | |
| - name: Generate autoloads | |
| run: php bin/php/ezpgenerateautoloads.php -s -e || true | |
| - name: Run PHPUnit | |
| run: vendor/bin/phpunit --colors=always | |
| - name: Clean CI Composer overlay | |
| if: always() | |
| run: rm -f "${CI_COMPOSER_FILE}" "${CI_COMPOSER_FILE%.json}.lock" | |
| phpunit-db: | |
| name: Database tests (${{ matrix.db }}, PHP ${{ matrix.php }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - php: '8.3' | |
| db: mysql | |
| dsn: 'mysql://root@127.0.0.1/testdb' | |
| - php: '8.3' | |
| db: postgresql | |
| dsn: 'postgresql://postgres@127.0.0.1/testdb' | |
| services: | |
| mysql: | |
| image: mysql:8.0 | |
| env: | |
| MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' | |
| MYSQL_DATABASE: testdb | |
| ports: | |
| - 3306:3306 | |
| options: >- | |
| --health-cmd="mysqladmin ping -h 127.0.0.1 -uroot" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=10 | |
| postgresql: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_DB: postgres | |
| POSTGRES_HOST_AUTH_METHOD: trust | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd="pg_isready -h 127.0.0.1 -U postgres -d postgres" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=10 | |
| env: | |
| TEST_DB_NAME: testdb | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| extensions: dom, libxml, mbstring, pcre, json, iconv, reflection, session, spl, simplexml, gd, mongodb, mysqli, pgsql, pdo_mysql, pdo_pgsql, pdo_sqlite, sqlite3, zip | |
| coverage: none | |
| tools: composer:v2 | |
| - name: Install system packages | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y imagemagick libbson-dev libmongoc-dev | |
| - name: Get Composer cache directory | |
| id: composer-cache-db | |
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.composer-cache-db.outputs.dir }} | |
| key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock', 'composer.json', '.github/workflows/phpunit.yml') }} | |
| restore-keys: ${{ runner.os }}-composer- | |
| - name: Install dependencies | |
| run: | | |
| cp composer.json "${CI_COMPOSER_FILE}" | |
| export PHPUNIT_VERSION="^11.5" | |
| php -r '$file = getenv("CI_COMPOSER_FILE"); $data = json_decode(file_get_contents($file), true, 512, JSON_THROW_ON_ERROR); if (($phpunit = getenv("PHPUNIT_VERSION")) !== false && $phpunit !== "") { $data["require-dev"]["phpunit/phpunit"] = $phpunit; } $data["require-dev"]["mongodb/mongodb"] = "^1.21 || ^2.0"; file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);' | |
| COMPOSER="${CI_COMPOSER_FILE}" composer update phpunit/phpunit --with-all-dependencies --prefer-dist --no-progress --no-interaction --ignore-platform-req=php --ignore-platform-req=ext-mongodb | |
| - name: Ensure vendor is present | |
| run: | | |
| if [[ ! -x vendor/bin/phpunit ]]; then | |
| echo "vendor/bin/phpunit is missing, reinstalling dependencies" | |
| COMPOSER="${CI_COMPOSER_FILE}" composer install --prefer-dist --no-progress --no-interaction --ignore-platform-req=php --ignore-platform-req=ext-mongodb | |
| fi | |
| test -x vendor/bin/phpunit | |
| - name: Generate autoloads | |
| run: php bin/php/ezpgenerateautoloads.php -s -e || true | |
| - name: Prepare database | |
| run: | | |
| case "${{ matrix.db }}" in | |
| mysql) | |
| mysql -h 127.0.0.1 -uroot -e "CREATE DATABASE IF NOT EXISTS ${TEST_DB_NAME};" | |
| ;; | |
| postgresql) | |
| psql -v ON_ERROR_STOP=1 -h 127.0.0.1 -U postgres -d postgres -c "CREATE DATABASE ${TEST_DB_NAME};" | |
| psql -v ON_ERROR_STOP=1 -h 127.0.0.1 -U postgres -d "${TEST_DB_NAME}" -c "CREATE EXTENSION IF NOT EXISTS pgcrypto;" | |
| ;; | |
| esac | |
| - name: Run database tests | |
| run: | | |
| # Keep DB suite timezone deterministic for CI stability. | |
| TEST_TIMEZONE=America/Los_Angeles | |
| echo "$TEST_TIMEZONE" | |
| php -d date.timezone="$TEST_TIMEZONE" tests/runtests.php --dsn "${{ matrix.dsn }}" --db-per-test tests extension/ezoe | |
| - name: Clean CI Composer overlay | |
| if: always() | |
| run: rm -f "${CI_COMPOSER_FILE}" "${CI_COMPOSER_FILE%.json}.lock" |