Skip to content

Commit

Permalink
Downgrade to PHP 7.4, move from Pest to PHPUnit, establish CI (#25)
Browse files Browse the repository at this point in the history
- Downgrades the lib to PHP 7.4
- Adds 'Check PHP CS == 7.4' step to GitHub Actions
- Replaces Pest with PHPUnit
- Rewrites RmStep tests in PHPUnit 
- Adds matrix unit tests step for all operating systems and all PHP
versions >= 7.4

 ### Caveats

- Dependencies versions are wildcards. This is inherently unstable, but
our true goal is to have stable 7.0 support. Establishing fixed versions
is a tedious job that does not seem crucial at this temporary step.
- Unit tests should include `prefer-lowest` as one of the arguments in
the `dependency_version` list. This will allow for the broadest version
support. But at this point in time it fails at 7.4. Fixing this serves
little purpose as, see logic above.
- Although we know PHPUnit 6.5 should be used, since this is the newest
versions supporting PHP == 7.0, PHPUnit 9.6 is used here. This is due to
all lower versions throwing the pesky `PHP Fatal error: Cannot acquire
reference to $GLOBALS`. This is still a step in the right direction as
writing PHPUnit tests in 9.6 and then downgrading them to 6.5 is still
easier, than writing in Pest and then going for PHPUnit 6.5.
- It should be analyzed if it is in fact beneficial to run the matrix
with each pull/pr. Alternatives: cron, only pr and more.


Co-authored-by: Adam Zieliński <[email protected]>
  • Loading branch information
reimic and adamziel authored Mar 4, 2024
1 parent b2ba54e commit 80786d8
Show file tree
Hide file tree
Showing 27 changed files with 2,081 additions and 2,606 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI

on:
push:
branches:
- trunk
pull_request:

jobs:
php-cs-check:
name: 'PHP 7.4 compatibility (via PHP Code Sniffer)'
runs-on: ubuntu-latest

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2
coverage: xdebug

- name: Install Dependencies
run: composer install --no-interaction --prefer-dist --optimize-autoloader

- name: Check PHP version compatibility
uses: pantheon-systems/phpcompatibility-action@v1
with:
skip-php-setup: true
test-versions: 7.4-
paths: ${{ github.workspace }}/src

test-unit:
needs: [php-cs-check]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
dependency_version: [ prefer-stable ]

name: ${{ matrix.os }} - PHP ${{ matrix.php }} - ${{ matrix.dependency_version }}

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none

- name: Install PHP dependencies
run: composer update --${{ matrix.dependency_version }} --no-interaction --prefer-dist --optimize-autoloader

- name: Run tests
run: ./vendor/bin/phpunit --testdox
42 changes: 27 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
{
"prefer-stable": true,
"require": {
"json-mapper/json-mapper": "^2.21",
"symfony/event-dispatcher": "^7.0",
"symfony/filesystem": "^7.0",
"symfony/process": "^7.0",
"symfony/http-client": "^7.0",
"symfony/http-kernel": "^7.0",
"pimple/pimple": "^3.0",
"psr/simple-cache": "^3.0",
"opis/json-schema": "^2.3"
"json-mapper/json-mapper": "*",
"symfony/event-dispatcher": "*",
"symfony/filesystem": "*",
"symfony/process": "*",
"symfony/http-client": "*",
"symfony/http-kernel": "*",
"pimple/pimple": "*",
"psr/simple-cache": "*",
"opis/json-schema": "*"
},
"require-dev": {
"pestphp/pest": "^2.33",
"nette/php-generator": "^4.1",
"jane-php/json-schema": "^7.6",
"bamarni/composer-bin-plugin": "^1.8"
"phpunit/phpunit": "*",
"squizlabs/php_codesniffer":"*",
"nette/php-generator": "*",
"jane-php/json-schema": "*",
"bamarni/composer-bin-plugin": "*",
"wp-coding-standards/wpcs": "3.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true,
"bamarni/composer-bin-plugin": true
"bamarni/composer-bin-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"platform": {
"php": "7.4"
}
},
"autoload": {
"classmap": [
"src/"
],
"psr-4": {
"WordPress\\": "src/WordPress",
"Symfony\\Component\\Process\\": "vendor/symfony/process"
Expand All @@ -35,5 +44,8 @@
"src/WordPress/Zip/functions.php",
"src/WordPress/Streams/stream_str_replace.php"
]
},
"scripts": {
"phpcs": "phpcs --standard=WordPress"
}
}
Loading

0 comments on commit 80786d8

Please sign in to comment.