From b55dc02876ce2e80bf8ea3c3f7fde4e17e02f1af Mon Sep 17 00:00:00 2001 From: remorhaz Date: Tue, 19 Sep 2023 15:42:33 +0300 Subject: [PATCH] CI switched to GitHub Actions --- .github/workflows/build.yml | 47 ++++++++++++++++++++++++++ .travis.yml | 27 --------------- README.md | 4 +-- composer.json | 6 ++-- tests/Parser/ParserTest.php | 14 +++++--- tests/Parser/TranslationSchemeTest.php | 45 ++++++++++++++---------- 6 files changed, 89 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0e06670 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,47 @@ +name: Build + +on: + - push + - workflow_dispatch + +jobs: + tests: + name: PHP ${{ matrix.php-version }} on ${{ matrix.os }} (${{ matrix.composer-options }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + php-version: + - "8.0" + - "8.1" + - "8.2" + os: + - ubuntu-latest + - windows-latest + - macOS-latest + composer-options: + - "" + - "--prefer-lowest" + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Set up PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: intl + coverage: xdebug + ini-values: error_reporting=E_ALL + + - name: Install dependencies + run: composer update + --prefer-dist + --no-progress + ${{ matrix.composer-options }} + + - name: Run tests + run: composer test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3913858..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: php - -env: - global: - - XDEBUG=YES - - XDEBUG_MODE=coverage - -jobs: - include: - - php: '7.3' - - php: '7.4' - - php: '8.0' - -install: - - mkdir -p ./build/logs - - composer install --prefer-source --no-interaction - - composer build - -script: - - vendor/bin/phpcs -sp --report-junit=build/logs/phpcs.xml - - if [ "$XDEBUG" == "YES" ]; then vendor/bin/phpunit --coverage-clover=build/logs/clover.xml --coverage-xml=build/logs/coverage-xml --log-junit=build/logs/junit.xml; else vendor/bin/phpunit; fi - - if [ "$XDEBUG" == "YES" ]; then vendor/bin/infection --coverage=build/logs --threads=4 --no-progress --skip-initial-tests; fi - -after_success: - - if [ "$XDEBUG" == "YES" ]; then bash <(curl -s https://codecov.io/bash -s "build/logs"); fi - - if [ "$XDEBUG" == "YES" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [ "$XDEBUG" == "YES" ]; then php ocular.phar code-coverage:upload --access-token=$SCRUTINIZER_TOKEN --format=php-clover build/logs/clover.xml; fi diff --git a/README.md b/README.md index eaf3e47..257b2e6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PHP JSON Pointer [![Latest Stable Version](https://poser.pugx.org/remorhaz/php-json-pointer/v/stable)](https://packagist.org/packages/remorhaz/php-json-pointer) -[![Build Status](https://travis-ci.org/remorhaz/php-json-pointer.svg?branch=master)](https://travis-ci.org/remorhaz/php-json-pointer) +[![Build](https://github.com/remorhaz/php-json-pointer/actions/workflows/build.yml/badge.svg)](https://github.com/remorhaz/php-json-pointer/actions/workflows/build.yml) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/remorhaz/php-json-pointer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/remorhaz/php-json-pointer/?branch=master) [![codecov](https://codecov.io/gh/remorhaz/php-json-pointer/branch/master/graph/badge.svg)](https://codecov.io/gh/remorhaz/php-json-pointer) [![Infection MSI](https://badge.stryker-mutator.io/github.com/remorhaz/php-json-pointer/master)](https://infection.github.io) @@ -11,7 +11,7 @@ This library implements [RFC6901](https://tools.ietf.org/html/rfc6901)-compliant JSON pointers. ## Requirements -* PHP 7.3+ +* PHP 8 ## Features * Selecting part of a JSON document. diff --git a/composer.json b/composer.json index 0bacc7a..2d44d0a 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,9 @@ "remorhaz/php-unilex": "^0.5.2" }, "require-dev": { - "phpunit/phpunit": "^9.5", - "infection/infection": "^0.18", - "squizlabs/php_codesniffer": "^3.5" + "phpunit/phpunit": "^9.6.13 || ^10", + "infection/infection": "^0.26.19 || ^0.27.2", + "squizlabs/php_codesniffer": "^3.7.2" }, "autoload": { "psr-4": { diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php index b7d2a6a..e273806 100644 --- a/tests/Parser/ParserTest.php +++ b/tests/Parser/ParserTest.php @@ -69,14 +69,20 @@ public function testBuildLocator_ConstructedWithReferenceFactory_UsesSameInstanc { $referenceFactory = $this->createMock(ReferenceFactoryInterface::class); $parser = new Parser(new Ll1ParserFactory(), $referenceFactory); + $textBuffer = []; $referenceFactory - ->expects(self::exactly(2)) ->method('createReference') - ->withConsecutive( - ['a'], - ['1'] + ->with( + self::callback( + function (string $text) use (&$textBuffer): bool { + $textBuffer[] = $text; + + return true; + }, + ), ); $parser->buildLocator('/a/1'); + self::assertSame(['a', '1'], $textBuffer); } /** diff --git a/tests/Parser/TranslationSchemeTest.php b/tests/Parser/TranslationSchemeTest.php index af1bfa3..fdf19b5 100644 --- a/tests/Parser/TranslationSchemeTest.php +++ b/tests/Parser/TranslationSchemeTest.php @@ -26,8 +26,8 @@ class TranslationSchemeTest extends TestCase { /** - * @param string $source - * @param list> $expectedValues + * @param string $source + * @param list $expectedValues * @throws UniLexException * @dataProvider providerValidBuffer */ @@ -37,11 +37,20 @@ public function testTranslation_ValidBuffer_BuildsMatchingLocator(string $source $scheme = new TranslationScheme($locatorBuilder); $parser = $this->createParser($scheme, $source); + $textBuffer = []; $locatorBuilder - ->expects(self::exactly(count($expectedValues))) ->method('addReference') - ->withConsecutive(...$expectedValues); + ->with( + self::callback( + function (string $text) use (&$textBuffer): bool { + $textBuffer[] = $text; + + return true; + }, + ), + ); $parser->run(); + self::assertSame($expectedValues, $textBuffer); } /** @@ -66,25 +75,25 @@ private function createParser(TranslationSchemeInterface $scheme, string $source } /** - * @return iterable>}> + * @return iterable}> */ public static function providerValidBuffer(): iterable { return [ 'Empty string' => ['', []], - 'Empty property' => ['/', [['']]], - 'Single alpha property' => ['/a', [['a']]], - 'Single numeric property' => ['/1', [['1']]], - 'Single non-ASCII property' => ['/б', [['б']]], - 'Property sequence' => ['/a/1', [['a'], ['1']]], - 'Escaped property sequence' => ['/~0/~1', [['~'], ['/']]], - 'Escaped tilde in a word' => ['/a~0b', [['a~b']]], - 'Escaped tilde in a word before zero' => ['/a~00', [['a~0']]], - 'Escaped tilde in a word before one' => ['/a~01', [['a~1']]], - 'Escaped slash in a word' => ['/a~1b', [['a/b']]], - 'Escaped slash in a word before zero' => ['/a~10', [['a/0']]], - 'Escaped tilde then escaped slash' => ['/~0~1', [['~/']]], - 'Escaped slash then escaped tilde' => ['/~1~0', [['/~']]], + 'Empty property' => ['/', ['']], + 'Single alpha property' => ['/a', ['a']], + 'Single numeric property' => ['/1', ['1']], + 'Single non-ASCII property' => ['/б', ['б']], + 'Property sequence' => ['/a/1', ['a', '1']], + 'Escaped property sequence' => ['/~0/~1', ['~', '/']], + 'Escaped tilde in a word' => ['/a~0b', ['a~b']], + 'Escaped tilde in a word before zero' => ['/a~00', ['a~0']], + 'Escaped tilde in a word before one' => ['/a~01', ['a~1']], + 'Escaped slash in a word' => ['/a~1b', ['a/b']], + 'Escaped slash in a word before zero' => ['/a~10', ['a/0']], + 'Escaped tilde then escaped slash' => ['/~0~1', ['~/']], + 'Escaped slash then escaped tilde' => ['/~1~0', ['/~']], ]; }