From 6d995a6e03295d05074f6fd65afcea829fc21cb0 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Thu, 10 Dec 2020 21:59:36 +0100 Subject: [PATCH] Add php 8 support (#1745) * Add php 8 support * Ignore platform reqs * Change php constraint * Use vendor/bin/simple-phpunit directly * Remove willdurand/hateoas-bundle when testing php8 * Merge 3.x * Move to github actions * Fix the tests * Change ./phpunit permissions * Update deprecations policy --- .github/workflows/continuous-integration.yml | 64 +++++++++++++++++++ .gitignore | 1 + .travis.yml | 38 ----------- CONTRIBUTING.md | 2 +- .../DependencyInjection/ConfigurationTest.php | 5 +- Tests/Describer/RouteDescriberTest.php | 2 +- Tests/Functional/ArrayItemsErrorTest.php | 2 +- Tests/Functional/BazingaFunctionalTest.php | 2 +- Tests/Functional/FOSRestTest.php | 2 +- Tests/Functional/FunctionalTest.php | 2 +- Tests/Functional/JMSFunctionalTest.php | 2 +- Tests/Functional/SwaggerUiTest.php | 2 +- .../FilteredRouteCollectionBuilderTest.php | 4 +- composer.json | 5 +- phpunit | 1 - 15 files changed, 81 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/continuous-integration.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..272fee9 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,64 @@ +# from doctrine/instantiator: +# https://github.com/doctrine/instantiator/blob/97aa11bb71ad6259a8c5a1161b4de2d6cdcc5501/.github/workflows/continuous-integration.yml + +name: "CI" + +on: + pull_request: + branches: + - "*.x" + push: + branches: + - "*.x" + +env: + fail-fast: true + COMPOSER_ROOT_VERSION: "1.4" + +jobs: + phpunit: + name: "PHPUnit" + runs-on: "ubuntu-20.04" + + strategy: + matrix: + include: + - php-version: 7.1 + composer-flags: "--prefer-lowest" + - php-version: 7.2 + symfony-require: "3.4.*" + - php-version: 7.3 + symfony-require: "4.4.*" + - php-version: 7.3 + symfony-require: "^5.0" + - php-version: 8.0 + composer-flags: "--ignore-platform-reqs" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + with: + fetch-depth: 2 + + - name: "Install PHP without coverage" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + coverage: "none" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + env: + SYMFONY_REQUIRE: "${{ matrix.symfony-require }}" + run: | + composer global require --no-progress --no-scripts --no-plugins symfony/flex + composer update --no-interaction --no-progress ${{ matrix.composer-flags }} + + - name: "Run PHPUnit" + run: "./phpunit" diff --git a/.gitignore b/.gitignore index d4acd14..ae94d3b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ /.php_cs /phpunit.xml /.phpunit +/.phpunit.result.cache /Tests/Functional/cache /Tests/Functional/logs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d8601ec..0000000 --- a/.travis.yml +++ /dev/null @@ -1,38 +0,0 @@ -language: php - -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -sudo: false - -cache: - directories: - - .phpunit - - $HOME/.composer/cache - -matrix: - fast_finish: true - include: - - php: 7.1 - env: COMPOSER_FLAGS="--prefer-lowest" - - php: 7.2 - env: SYMFONY_VERSION=^3.4 - - php: 7.3 - env: SYMFONY_VERSION=^4.0 - - php: 7.3 - env: SYMFONY_VERSION=^5.0 - - php: 7.4 - env: SYMFONY_VERSION=^4.0 - - php: 7.4 - env: SYMFONY_VERSION=^5.0 - -before_install: - - phpenv config-rm xdebug.ini || true - - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --dev --no-update; fi; - -install: composer update --no-interaction $COMPOSER_FLAGS - -script: ./phpunit diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 75f90ec..18bf10e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ You MUST follow the [PSR-1](http://www.php-fig.org/psr/psr-1/) and should really read the recommendations. Can't wait? Use the [PHP-CS-Fixer tool](http://cs.sensiolabs.org/). -You MUST run the test suite. +You MUST run the test suite (run `composer update`, and then execute `vendor/bin/simple-phpunit`). You MUST write (or update) unit tests. diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 5c9509b..3a7d545 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -147,11 +147,12 @@ class ConfigurationTest extends TestCase /** * @group legacy - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage You must not use both `nelmio_api_doc.areas` and `nelmio_api_doc.routes` config options. Please update your config to only use `nelmio_api_doc.areas`. */ public function testBothAreasAndRoutes() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('You must not use both `nelmio_api_doc.areas` and `nelmio_api_doc.routes` config options. Please update your config to only use `nelmio_api_doc.areas`.'); + $processor = new Processor(); $config = $processor->processConfiguration(new Configuration(), [['areas' => [], 'routes' => []]]); } diff --git a/Tests/Describer/RouteDescriberTest.php b/Tests/Describer/RouteDescriberTest.php index b21baaf..e995291 100644 --- a/Tests/Describer/RouteDescriberTest.php +++ b/Tests/Describer/RouteDescriberTest.php @@ -35,7 +35,7 @@ class RouteDescriberTest extends AbstractDescriberTest $this->assertEquals((new Swagger())->toArray(), $this->getSwaggerDoc()->toArray()); } - protected function setUp() + protected function setUp(): void { $this->routeDescriber = $this->createMock(RouteDescriberInterface::class); $this->routes = new RouteCollection(); diff --git a/Tests/Functional/ArrayItemsErrorTest.php b/Tests/Functional/ArrayItemsErrorTest.php index 24acb63..cd8214e 100644 --- a/Tests/Functional/ArrayItemsErrorTest.php +++ b/Tests/Functional/ArrayItemsErrorTest.php @@ -15,7 +15,7 @@ use Nelmio\ApiDocBundle\Exception\UndocumentedArrayItemsException; class ArrayItemsErrorTest extends WebTestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Functional/BazingaFunctionalTest.php b/Tests/Functional/BazingaFunctionalTest.php index ab82fe6..6be482b 100644 --- a/Tests/Functional/BazingaFunctionalTest.php +++ b/Tests/Functional/BazingaFunctionalTest.php @@ -15,7 +15,7 @@ use Hateoas\Configuration\Embedded; class BazingaFunctionalTest extends WebTestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Functional/FOSRestTest.php b/Tests/Functional/FOSRestTest.php index 2ddf417..1e9c695 100644 --- a/Tests/Functional/FOSRestTest.php +++ b/Tests/Functional/FOSRestTest.php @@ -13,7 +13,7 @@ namespace Nelmio\ApiDocBundle\Tests\Functional; class FOSRestTest extends WebTestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index 5759256..d501ff8 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -16,7 +16,7 @@ use Symfony\Component\Serializer\Annotation\SerializedName; class FunctionalTest extends WebTestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Functional/JMSFunctionalTest.php b/Tests/Functional/JMSFunctionalTest.php index 1532ca0..5645f0f 100644 --- a/Tests/Functional/JMSFunctionalTest.php +++ b/Tests/Functional/JMSFunctionalTest.php @@ -13,7 +13,7 @@ namespace Nelmio\ApiDocBundle\Tests\Functional; class JMSFunctionalTest extends WebTestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Functional/SwaggerUiTest.php b/Tests/Functional/SwaggerUiTest.php index 0b32453..209db31 100644 --- a/Tests/Functional/SwaggerUiTest.php +++ b/Tests/Functional/SwaggerUiTest.php @@ -20,7 +20,7 @@ class SwaggerUiTest extends WebTestCase */ private $client; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Routing/FilteredRouteCollectionBuilderTest.php b/Tests/Routing/FilteredRouteCollectionBuilderTest.php index f8d01c1..8a782f3 100644 --- a/Tests/Routing/FilteredRouteCollectionBuilderTest.php +++ b/Tests/Routing/FilteredRouteCollectionBuilderTest.php @@ -84,12 +84,12 @@ class FilteredRouteCollectionBuilderTest extends TestCase } /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidArgumentException - * * @dataProvider getInvalidOptions */ public function testFilterWithInvalidOption(array $options) { + $this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidArgumentException::class); + new FilteredRouteCollectionBuilder( new AnnotationReader(), $this->createControllerReflector(), diff --git a/composer.json b/composer.json index f22eada..c1832c5 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "^7.1", + "php": ">=7.1.3", "symfony/framework-bundle": "^3.4|^4.0|^5.0", "symfony/options-resolver": "^3.4.4|^4.0|^5.0", "symfony/property-info": "^3.4|^4.0|^5.0", @@ -30,6 +30,7 @@ "symfony/console": "^3.4|^4.0|^5.0", "symfony/config": "^3.4|^4.0|^5.0", "symfony/validator": "^3.4|^4.0|^5.0", + "symfony/expression-language": "^3.4|^4.0|^5.0", "symfony/property-access": "^3.4|^4.0|^5.0", "symfony/form": "^3.4|^4.0|^5.0", "symfony/dom-crawler": "^3.4|^4.0|^5.0", @@ -43,7 +44,7 @@ "doctrine/common": "^2.4", "api-platform/core": "^2.1.2", - "friendsofsymfony/rest-bundle": "^2.0|^3.0@beta", + "friendsofsymfony/rest-bundle": "^2.0|^3.0@dev", "willdurand/hateoas-bundle": "^1.0|^2.0", "jms/serializer-bundle": "^2.3|^3.0", "jms/serializer": "^1.14|^3.0" diff --git a/phpunit b/phpunit index 2934e5b..ffa70d2 100755 --- a/phpunit +++ b/phpunit @@ -5,5 +5,4 @@ if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) { exit(1); } putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit'); -putenv('SYMFONY_PHPUNIT_VERSION=6.5'); require __DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit';