From accb39d8ddb5e54d7c6c92f65781eb82a3854cde Mon Sep 17 00:00:00 2001 From: Jeremiasz Major Date: Mon, 29 Aug 2022 18:55:24 +0200 Subject: [PATCH 1/3] Move CI from Travis to GitHub --- .github/workflows/ci.yml | 86 +++++++++++++++++++ .github/workflows/sca.yml | 55 ++++++++++++ .travis.yml | 63 -------------- .../check_trailing_spaces.sh | 0 run-tests.sh | 40 --------- tests/AutoReviewTest.php | 26 ++++-- 6 files changed, 159 insertions(+), 111 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/sca.yml delete mode 100644 .travis.yml rename check_trailing_spaces.sh => dev-tools/check_trailing_spaces.sh (100%) delete mode 100755 run-tests.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..fc3b124 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,86 @@ +name: CI + +on: + - pull_request + - push + +jobs: + tests: + strategy: + fail-fast: false + matrix: + include: + - phpunit-version: 4 + php-version: '5.5' + - phpunit-version: 4 + php-version: '5.6' + - phpunit-version: 5 + php-version: '5.6' + - phpunit-version: 5 + php-version: '7.0' + - phpunit-version: 5 + php-version: '7.1' + - phpunit-version: 6 + php-version: '7.0' + - phpunit-version: 6 + php-version: '7.1' + - phpunit-version: 6 + php-version: '7.2' + - phpunit-version: 7 + php-version: '7.1' + - phpunit-version: 7 + php-version: '7.2' + - phpunit-version: 7 + php-version: '7.3' + - phpunit-version: 8 + php-version: '7.2' + - phpunit-version: 8 + php-version: '7.3' + - phpunit-version: 8 + php-version: '7.4' + - phpunit-version: 8 + php-version: '8.0' + - phpunit-version: 8 + php-version: '8.1' + - phpunit-version: 9 + php-version: '7.3' + - phpunit-version: 9 + php-version: '7.4' + - phpunit-version: 9 + php-version: '8.0' + - phpunit-version: 9 + php-version: '8.1' + + name: PHPUnit ${{ matrix.phpunit-version }} on PHP ${{ matrix.php-version }} + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + + - name: Get Composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: composer-${{ matrix.php-version }}-${{ hashFiles('composer.*') }} + restore-keys: | + composer-${{ matrix.php-version }}- + composer- + + - name: Install dependencies + run: | + composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }} + composer update phpunit/phpunit:^${{ matrix.phpunit-version }} sanmai/phpunit-legacy-adapter --with-all-dependencies ${{ matrix.composer-flags }} + + - name: Run tests + run: vendor/bin/phpunit diff --git a/.github/workflows/sca.yml b/.github/workflows/sca.yml new file mode 100644 index 0000000..708b444 --- /dev/null +++ b/.github/workflows/sca.yml @@ -0,0 +1,55 @@ +name: Static Code Analysis + +on: + - pull_request + - push + +jobs: + tests: + name: Static Code Analysis + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + + - name: Get Composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: dev-tools-${{ hashFiles('dev-tools/composer.*') }} + restore-keys: | + dev-tools- + + - name: Install dev tools + run: | + composer update --optimize-autoloader --no-interaction --no-progress -d dev-tools + + - name: Check - trailing spaces + run: ./dev-tools/check_trailing_spaces.sh + + - name: Check - composer validate + run: composer validate --strict + + - name: Check - composer normalize + run: composer normalize --dry-run --working-dir=./dev-tools composer.json + + - name: Check - composer-require-checker + run: ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file .composer-require-checker.json + continue-on-error: true + + - name: Check - phpmd + run: ./dev-tools/vendor/bin/phpmd src,tests text phpmd.xml + + - name: Check - PhpCsFixer + run: ./dev-tools/vendor/bin/php-cs-fixer fix --diff --dry-run -v diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fd94d35..0000000 --- a/.travis.yml +++ /dev/null @@ -1,63 +0,0 @@ -sudo: false - -git: - depth: 1 - -cache: - directories: - - $HOME/.composer - -language: php - -php: - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - nightly - -env: - global: - - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-progress" - -stages: - - Static code analysis - - Test - -before_install: - # turn off XDebug - - phpenv config-rm xdebug.ini || return 0 - - # Composer: boost installation - - composer global show -ND 2>&1 | grep "hirak/prestissimo" || travis_retry composer global require $DEFAULT_COMPOSER_FLAGS hirak/prestissimo - -install: skip - -script: - - ./run-tests.sh ^4.8.36 || travis_terminate 1 - - ./run-tests.sh ^5.7.27 || travis_terminate 1 - - ./run-tests.sh ^6.5.14 || travis_terminate 1 - - ./run-tests.sh ^7.5.20 || travis_terminate 1 - - ./run-tests.sh ~8.5 || travis_terminate 1 - - ./run-tests.sh ~9.4 || travis_terminate 1 - -jobs: - include: - - - stage: Static code analysis - php: 7.3 - install: - - travis_retry composer update $DEFAULT_COMPOSER_FLAGS - - travis_retry composer update -d dev-tools $DEFAULT_COMPOSER_FLAGS - - composer info -d dev-tools -D | sort - script: - - ./check_trailing_spaces.sh || travis_terminate 1 - - composer validate --strict || travis_terminate 1 - - composer normalize -d ./dev-tools ./../composer.json --dry-run || travis_terminate 1 - # disabled due to PHPUnit issues: https://github.com/sebastianbergmann/phpunit/issues/4450 - # - ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file=.composer-require-checker.json || travis_terminate 1 - - ./dev-tools/vendor/bin/phpmd src,tests text phpmd.xml || travis_terminate 1 - - ./dev-tools/vendor/bin/php-cs-fixer fix --diff --dry-run -v || travis_terminate 1 diff --git a/check_trailing_spaces.sh b/dev-tools/check_trailing_spaces.sh similarity index 100% rename from check_trailing_spaces.sh rename to dev-tools/check_trailing_spaces.sh diff --git a/run-tests.sh b/run-tests.sh deleted file mode 100755 index fecf4ed..0000000 --- a/run-tests.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -set -e - -PHPUNIT=$1 -INSTALLED=0 - -if [ -z "${PHPUNIT}" ] -then - echo -e "\e[101mNo PHPUnit version provided.\e[0m" - exit 1 -fi - -echo -e "\e[46m§ Trying to execute tests under PHPUnit ${PHPUNIT}.\e[0m" - -rm -f composer.lock - -echo -e "\n\e[46m§ Installing deps...\e[0m" -if [ ${PHPUNIT:1:1} == 8 ] -then - composer require -q --dev --no-update friendsofphp/php-cs-fixer || return 0 -fi -composer require -q --dev --no-update phpunit/phpunit:${PHPUNIT} && composer update -q $DEFAULT_COMPOSER_FLAGS && INSTALLED=1 || INSTALLED=0 -if [ $INSTALLED == 1 ] && [ ${PHPUNIT:1:1} == 8 ] -then - PHP_CS_FIXER_FUTURE_MODE=1 vendor/bin/php-cs-fixer fix --rules=void_return -q tests -fi -git checkout composer.json - -if [ $INSTALLED == 0 ] -then - echo -e "\n\e[45mPHPUnit ${PHPUNIT}: Is not compatible with $(php -v | head -1).\e[0m" -else - echo -e "\n\e[46m§ Installed:\e[0m" - composer info -D | sort - - echo -e "\n\e[46m§ Running tests...\e[0m" - vendor/bin/phpunit -v || (echo -e "\n\e[41mPHPUnit ${PHPUNIT}: Error while testing.\e[0m" && exit 2) - - echo -e "\n\e[42mPHPUnit ${PHPUNIT}: Success.\e[0m" -fi diff --git a/tests/AutoReviewTest.php b/tests/AutoReviewTest.php index 87cfb0c..65ae72b 100644 --- a/tests/AutoReviewTest.php +++ b/tests/AutoReviewTest.php @@ -20,13 +20,23 @@ final class AutoReviewTest extends TestCase { public function testThatThereIsProperPHPUnitInComposer() { - $json = json_decode(file_get_contents(__DIR__.'/../composer.json'), true); - $yaml = file_get_contents(__DIR__.'/../.travis.yml', FILE_IGNORE_NEW_LINES); - preg_match_all('/run-tests\.sh (\S+)/', $yaml, $matches); - - static::assertSame( - implode(' || ', $matches[1]), - $json['require']['phpunit/phpunit'] - ); + $requirements = file_get_contents(__DIR__.'/../composer.json'); + $requirements = json_decode($requirements, true)['require']['phpunit/phpunit']; + + $yml = file_get_contents(__DIR__.'/../.github/workflows/ci.yml'); + + preg_match_all('/phpunit-version: (\S+)/', $yml, $matches); + + $testedVersions = array_unique($matches[1]); + + foreach (explode(' || ', $requirements) as $version) { + preg_match('/^[\^~](\d+)\.\d+(?:\.\d+)?$/', $version, $match); + + self::assertContains( + $majorVersion = $match[1], + $testedVersions, + "PHPUnit {$majorVersion} is allowed in composer.json, but not present in the test matrix at .github/workflows/ci.yml." + ); + } } } From 6b544cfbbeec216cad22974ace0b8e47dff235e8 Mon Sep 17 00:00:00 2001 From: Jeremiasz Major Date: Mon, 29 Aug 2022 19:03:39 +0200 Subject: [PATCH 2/3] Fix for sebastianbergmann/phpunit#5033 --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 3554e2f..3be488e 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ "phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ~8.5 || ~9.4" }, "require-dev": { + "phpspec/prophecy": "^1.10", "phpunitgoodpractices/polyfill": "^1.1", "sanmai/phpunit-legacy-adapter": "^6.1 || ^8.0" }, From 2364e4e69199592aaf1fa324b908f94e07ccbbf9 Mon Sep 17 00:00:00 2001 From: Jeremiasz Major Date: Sun, 21 Aug 2022 15:48:19 +0200 Subject: [PATCH 3/3] Formatting --- tests/AutoReviewTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/AutoReviewTest.php b/tests/AutoReviewTest.php index 65ae72b..9702dc5 100644 --- a/tests/AutoReviewTest.php +++ b/tests/AutoReviewTest.php @@ -32,7 +32,7 @@ public function testThatThereIsProperPHPUnitInComposer() foreach (explode(' || ', $requirements) as $version) { preg_match('/^[\^~](\d+)\.\d+(?:\.\d+)?$/', $version, $match); - self::assertContains( + static::assertContains( $majorVersion = $match[1], $testedVersions, "PHPUnit {$majorVersion} is allowed in composer.json, but not present in the test matrix at .github/workflows/ci.yml."