From fbd753e2001134d6f51318cd299d0a055761592c Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 25 Jul 2024 12:56:20 +0200 Subject: [PATCH] Upgrade PHPUnit and add PHP 8.4 to CI (#134) * Upgrade PHPUnit and add PHP 8.4 to CI * Remove unnecessary conflicts * Use prophecy trait * Add PHPUnit bridge * Use prophecy-phpunit 2 * Update phpunit file * Update PHPUnit * Move lint to own CI task * Add CI for lowest version * Move phpstan config from composer.json to phpstan.neon file * Update lowest task * Fix lowest CI * Remove not longer required gedmo hack --- .env.dist | 24 ------- .github/workflows/test-application.yaml | 65 ++++++++++++++++--- Tests/Application/Kernel.php | 8 +++ Tests/Application/config/config.yml | 2 +- .../Adapter/ImageMediaAdapterTest.php | 2 + Tests/Unit/Entity/ImageMediaBridgeTest.php | 3 + Tests/Unit/Entity/TaxonCategoryBridgeTest.php | 3 + .../RemoveProductMessageHandlerTest.php | 3 + ...RemoveProductVariantMessageHandlerTest.php | 3 + .../Handler/RemoveTaxonMessageHandlerTest.php | 3 + .../SynchronizeImageMessageHandlerTest.php | 3 + .../SynchronizeProductMessageHandlerTest.php | 3 + ...ronizeProductVariantMessageHandlerTest.php | 3 + .../SynchronizeTaxonsMessageHandlerTest.php | 3 + composer.json | 32 ++++----- phpstan.neon | 3 +- phpunit-9.xml.dist | 23 +++++++ phpunit.xml.dist | 22 ++++--- 18 files changed, 151 insertions(+), 57 deletions(-) delete mode 100644 .env.dist create mode 100644 phpunit-9.xml.dist diff --git a/.env.dist b/.env.dist deleted file mode 100644 index 54ebbd81..00000000 --- a/.env.dist +++ /dev/null @@ -1,24 +0,0 @@ -# This file is a "template" of which env vars need to be defined for your application -# Copy this file to .env file for development, create environment variables when deploying to production -# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration - -###> symfony/framework-bundle ### -APP_ENV=dev -APP_SECRET= -#TRUSTED_PROXIES=127.0.0.1,127.0.0.2 -#TRUSTED_HOSTS=localhost,example.com -###< symfony/framework-bundle ### - -###> symfony/swiftmailer-bundle ### -# For Gmail as a transport, use: "gmail://username:password@localhost" -# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" -# Delivery is disabled by default via "null://localhost" -MAILER_URL=null://localhost -###< symfony/swiftmailer-bundle ### - -###> doctrine/doctrine-bundle ### -# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url -# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db" -# Configure your db driver and server_version in config/packages/doctrine.yaml -DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/su_sylius_test -###< doctrine/doctrine-bundle ### \ No newline at end of file diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index cbdc83d1..3d8c347b 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -13,17 +13,27 @@ jobs: runs-on: ubuntu-latest env: - DATABASE_URL: mysql://root:root@127.0.0.1:3306/sulu_test?serverVersion=5.7 + DATABASE_URL: mysql://root:root@127.0.0.1:3306/sulu_test?serverVersion=8.0 strategy: fail-fast: false matrix: include: + - php-version: '7.4' + dependency-versions: 'lowest' + php-extensions: 'ctype, iconv, mysql, imagick' + tools: 'composer:v2' + lint: false + phpunit-config: 'phpunit-9.xml.dist' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + - php-version: '7.4' dependency-versions: 'highest' php-extensions: 'ctype, iconv, mysql, imagick' tools: 'composer:v2' lint: false + phpunit-config: 'phpunit-9.xml.dist' env: SYMFONY_DEPRECATIONS_HELPER: weak @@ -55,6 +65,14 @@ jobs: lint: true env: SYMFONY_DEPRECATIONS_HELPER: weak + - php-version: '8.4' + dependency-versions: 'highest' + composer-options: '--ignore-platform-reqs' + php-extensions: 'ctype, iconv, mysql, imagick' + tools: 'composer:v2' + lint: true + env: + SYMFONY_DEPRECATIONS_HELPER: weak services: mysql: @@ -67,7 +85,7 @@ jobs: steps: - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -77,20 +95,51 @@ jobs: tools: ${{ matrix.tools }} coverage: none + - name: Allow old composer plugin + run: composer config --no-plugins allow-plugins.ocramius/package-versions true # todo remove when not longer required for lowest task + + - name: Remove Lint Tools + # These tools are not required to run tests, so we are removing them to improve dependency resolving and + # testing lowest versions. + run: composer remove "*php-cs-fixer*" "*phpstan*" "*rector*" --dev --no-update + - name: Install composer dependencies uses: ramsey/composer-install@v2 with: dependency-versions: ${{matrix.dependency-versions}} + composer-options: ${{matrix.composer-options}} - name: Bootstrap test environment run: composer initialize env: ${{ matrix.env }} - - name: Lint code - if: ${{ matrix.lint }} - run: composer lint - env: ${{ matrix.env }} - - name: Execute test cases - run: time composer test + run: time composer test -- --config ${{ matrix.phpunit-config || 'phpunit.xml.dist' }} env: ${{ matrix.env }} + + lint: + name: "PHP Lint" + runs-on: ubuntu-latest + + env: + DATABASE_URL: mysql://root:root@127.0.0.1:3306/sulu_test?serverVersion=8.0 + + steps: + - name: Checkout project + uses: actions/checkout@v4 + + - name: Install and configure PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.3 + extensions: 'ctype, iconv, mysql, imagick' + tools: 'composer:v2' + coverage: none + + - name: Install composer dependencies + uses: ramsey/composer-install@v2 + with: + dependency-versions: highest + + - name: Lint code + run: composer lint diff --git a/Tests/Application/Kernel.php b/Tests/Application/Kernel.php index 9eb03418..dedd78fe 100644 --- a/Tests/Application/Kernel.php +++ b/Tests/Application/Kernel.php @@ -37,4 +37,12 @@ public function registerContainerConfiguration(LoaderInterface $loader): void $loader->load(__DIR__ . '/config/config_' . $this->getContext() . '.yml'); } + + protected function getKernelParameters(): array + { + $parameters = parent::getKernelParameters(); + $parameters['kernel.root_dir'] = __DIR__; // TODO remove when lowest version increased + + return $parameters; + } } diff --git a/Tests/Application/config/config.yml b/Tests/Application/config/config.yml index 409ee138..70bf7b70 100644 --- a/Tests/Application/config/config.yml +++ b/Tests/Application/config/config.yml @@ -31,4 +31,4 @@ services: sulu_media.storage: class: Sulu\Bundle\SyliusConsumerBundle\Tests\Functional\Mocks\Storage - public: true \ No newline at end of file + public: true diff --git a/Tests/Functional/Adapter/ImageMediaAdapterTest.php b/Tests/Functional/Adapter/ImageMediaAdapterTest.php index 35ca335e..5400f3c5 100644 --- a/Tests/Functional/Adapter/ImageMediaAdapterTest.php +++ b/Tests/Functional/Adapter/ImageMediaAdapterTest.php @@ -16,6 +16,7 @@ use Doctrine\ORM\Id\AssignedGenerator; use Doctrine\ORM\Mapping\ClassMetadata; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\MediaBundle\Entity\CollectionType; use Sulu\Bundle\MediaBundle\Entity\MediaType; @@ -33,6 +34,7 @@ class ImageMediaAdapterTest extends KernelTestCase { + use ProphecyTrait; use PurgeDatabaseTrait; /** diff --git a/Tests/Unit/Entity/ImageMediaBridgeTest.php b/Tests/Unit/Entity/ImageMediaBridgeTest.php index 39494899..df253a5d 100644 --- a/Tests/Unit/Entity/ImageMediaBridgeTest.php +++ b/Tests/Unit/Entity/ImageMediaBridgeTest.php @@ -14,11 +14,14 @@ namespace Sulu\Bundle\SyliusConsumerBundle\Tests\Unit\Entity; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\MediaBundle\Entity\MediaInterface; use Sulu\Bundle\SyliusConsumerBundle\Entity\ImageMediaBridge; class ImageMediaBridgeTest extends TestCase { + use ProphecyTrait; + public function testGetId(): void { $media = $this->prophesize(MediaInterface::class); diff --git a/Tests/Unit/Entity/TaxonCategoryBridgeTest.php b/Tests/Unit/Entity/TaxonCategoryBridgeTest.php index bdfebea8..f564d176 100644 --- a/Tests/Unit/Entity/TaxonCategoryBridgeTest.php +++ b/Tests/Unit/Entity/TaxonCategoryBridgeTest.php @@ -14,11 +14,14 @@ namespace Sulu\Bundle\SyliusConsumerBundle\Tests\Unit\Entity; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\CategoryBundle\Entity\CategoryInterface; use Sulu\Bundle\SyliusConsumerBundle\Entity\TaxonCategoryBridge; class TaxonCategoryBridgeTest extends TestCase { + use ProphecyTrait; + public function testGetId(): void { $category = $this->prophesize(CategoryInterface::class); diff --git a/Tests/Unit/Handler/RemoveProductMessageHandlerTest.php b/Tests/Unit/Handler/RemoveProductMessageHandlerTest.php index 5addf81d..36dd3bb8 100644 --- a/Tests/Unit/Handler/RemoveProductMessageHandlerTest.php +++ b/Tests/Unit/Handler/RemoveProductMessageHandlerTest.php @@ -14,12 +14,15 @@ namespace Sulu\Bundle\SyliusConsumerBundle\Tests\Unit\Handler; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\SyliusConsumerBundle\Adapter\ProductAdapterInterface; use Sulu\Bundle\SyliusConsumerBundle\Handler\RemoveProductMessageHandler; use Sulu\Bundle\SyliusConsumerBundle\Message\RemoveProductMessage; class RemoveProductMessageHandlerTest extends TestCase { + use ProphecyTrait; + public function testInvoke(): void { $adapter1 = $this->prophesize(ProductAdapterInterface::class); diff --git a/Tests/Unit/Handler/RemoveProductVariantMessageHandlerTest.php b/Tests/Unit/Handler/RemoveProductVariantMessageHandlerTest.php index 61635bc0..c38d4252 100644 --- a/Tests/Unit/Handler/RemoveProductVariantMessageHandlerTest.php +++ b/Tests/Unit/Handler/RemoveProductVariantMessageHandlerTest.php @@ -14,12 +14,15 @@ namespace Sulu\Bundle\SyliusConsumerBundle\Tests\Unit\Handler; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\SyliusConsumerBundle\Adapter\ProductVariantAdapterInterface; use Sulu\Bundle\SyliusConsumerBundle\Handler\RemoveProductVariantMessageHandler; use Sulu\Bundle\SyliusConsumerBundle\Message\RemoveProductVariantMessage; class RemoveProductVariantMessageHandlerTest extends TestCase { + use ProphecyTrait; + public function testInvoke(): void { $adapter1 = $this->prophesize(ProductVariantAdapterInterface::class); diff --git a/Tests/Unit/Handler/RemoveTaxonMessageHandlerTest.php b/Tests/Unit/Handler/RemoveTaxonMessageHandlerTest.php index 39e7105b..4943c36f 100644 --- a/Tests/Unit/Handler/RemoveTaxonMessageHandlerTest.php +++ b/Tests/Unit/Handler/RemoveTaxonMessageHandlerTest.php @@ -14,12 +14,15 @@ namespace Sulu\Bundle\SyliusConsumerBundle\Tests\Unit\Handler; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\SyliusConsumerBundle\Adapter\TaxonAdapterInterface; use Sulu\Bundle\SyliusConsumerBundle\Handler\RemoveTaxonMessageHandler; use Sulu\Bundle\SyliusConsumerBundle\Message\RemoveTaxonMessage; class RemoveTaxonMessageHandlerTest extends TestCase { + use ProphecyTrait; + public function testInvoke(): void { $adapter1 = $this->prophesize(TaxonAdapterInterface::class); diff --git a/Tests/Unit/Handler/SynchronizeImageMessageHandlerTest.php b/Tests/Unit/Handler/SynchronizeImageMessageHandlerTest.php index f757ef24..7932cae5 100644 --- a/Tests/Unit/Handler/SynchronizeImageMessageHandlerTest.php +++ b/Tests/Unit/Handler/SynchronizeImageMessageHandlerTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\SyliusConsumerBundle\Adapter\ImageAdapterInterface; use Sulu\Bundle\SyliusConsumerBundle\Handler\SynchronizeImageMessageHandler; use Sulu\Bundle\SyliusConsumerBundle\Message\SynchronizeImageMessage; @@ -22,6 +23,8 @@ class SynchronizeImageMessageHandlerTest extends TestCase { + use ProphecyTrait; + public function testInvoke(): void { $adapter1 = $this->prophesize(ImageAdapterInterface::class); diff --git a/Tests/Unit/Handler/SynchronizeProductMessageHandlerTest.php b/Tests/Unit/Handler/SynchronizeProductMessageHandlerTest.php index b4a90b5e..f414051b 100644 --- a/Tests/Unit/Handler/SynchronizeProductMessageHandlerTest.php +++ b/Tests/Unit/Handler/SynchronizeProductMessageHandlerTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\SyliusConsumerBundle\Adapter\ProductAdapterInterface; use Sulu\Bundle\SyliusConsumerBundle\Handler\SynchronizeProductMessageHandler; use Sulu\Bundle\SyliusConsumerBundle\Message\SynchronizeProductMessage; @@ -22,6 +23,8 @@ class SynchronizeProductMessageHandlerTest extends TestCase { + use ProphecyTrait; + public function testInvoke(): void { $adapter1 = $this->prophesize(ProductAdapterInterface::class); diff --git a/Tests/Unit/Handler/SynchronizeProductVariantMessageHandlerTest.php b/Tests/Unit/Handler/SynchronizeProductVariantMessageHandlerTest.php index b762ae53..f6a6e27a 100644 --- a/Tests/Unit/Handler/SynchronizeProductVariantMessageHandlerTest.php +++ b/Tests/Unit/Handler/SynchronizeProductVariantMessageHandlerTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\SyliusConsumerBundle\Adapter\ProductVariantAdapterInterface; use Sulu\Bundle\SyliusConsumerBundle\Handler\SynchronizeProductVariantMessageHandler; use Sulu\Bundle\SyliusConsumerBundle\Message\SynchronizeProductVariantMessage; @@ -22,6 +23,8 @@ class SynchronizeProductVariantMessageHandlerTest extends TestCase { + use ProphecyTrait; + public function testInvoke(): void { $adapter1 = $this->prophesize(ProductVariantAdapterInterface::class); diff --git a/Tests/Unit/Handler/SynchronizeTaxonsMessageHandlerTest.php b/Tests/Unit/Handler/SynchronizeTaxonsMessageHandlerTest.php index 59b6e400..23e6db63 100644 --- a/Tests/Unit/Handler/SynchronizeTaxonsMessageHandlerTest.php +++ b/Tests/Unit/Handler/SynchronizeTaxonsMessageHandlerTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\SyliusConsumerBundle\Adapter\TaxonAdapterInterface; use Sulu\Bundle\SyliusConsumerBundle\Handler\SynchronizeTaxonsMessageHandler; use Sulu\Bundle\SyliusConsumerBundle\Message\SynchronizeTaxonsMessage; @@ -22,6 +23,8 @@ class SynchronizeTaxonsMessageHandlerTest extends TestCase { + use ProphecyTrait; + public function testInvoke(): void { $adapter1 = $this->prophesize(TaxonAdapterInterface::class); diff --git a/composer.json b/composer.json index bb490eca..afc5eab8 100644 --- a/composer.json +++ b/composer.json @@ -12,34 +12,33 @@ "license": "MIT", "require": { "php": "^7.2|^8.0", - "sulu/sulu": "^2.1 || 2.x-dev", - "symfony/config": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/http-kernel": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/messenger": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "sulu/sulu": "^2.4 || 2.x-dev", + "symfony/config": "^5.4 || ^6.0 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0", + "symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.0 || ^7.0", + "symfony/messenger": "^5.4 || ^6.0 || ^7.0", "webmozart/assert": "^1.9" }, "require-dev": { - "php-cs-fixer/shim": "^3.9", "handcraftedinthealps/zendsearch": "^2.0", "jackalope/jackalope-doctrine-dbal": "^1.3.4|| ^2.0", "jangregor/phpstan-prophecy": "^1.0", + "php-cs-fixer/shim": "^3.9", "phpspec/prophecy": "^1.15", + "phpspec/prophecy-phpunit": "^2.0", "phpstan/phpstan": "^1.0", "phpstan/phpstan-doctrine": "^1.0", "phpstan/phpstan-symfony": "^1.0", "phpstan/phpstan-webmozart-assert": "^1.0", - "phpunit/phpunit": "^8.2", - "symfony/browser-kit": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/dotenv": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/error-handler": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "phpunit/phpunit": "^9.6.20 || ^10.5.28", + "symfony/browser-kit": "^5.4 || ^6.0 || ^7.0", + "symfony/dotenv": "^5.4 || ^6.0 || ^7.0", + "symfony/error-handler": "^5.4 || ^6.0 || ^7.0", "symfony/monolog-bundle": "^3.3" }, "conflict": { - "symfony/dependency-injection": "4.1.8", - "symfony/symfony": "4.2.7", - "symfony/framework-bundle": "4.2.7" + "dantleech/phpcr-migrations-bundle": "<1.3.0" }, "config": { "sort-packages": true, @@ -66,7 +65,10 @@ "@php-cs" ], "phpunit": "vendor/bin/phpunit", - "phpstan": "vendor/bin/phpstan analyze -c ./phpstan.neon . -l 5", + "phpstan": [ + "Tests/Application/console cache:warmup --env dev", + "vendor/bin/phpstan analyze -c ./phpstan.neon" + ], "php-cs": "vendor/bin/php-cs-fixer fix --verbose --diff --dry-run", "php-cs-fix": "vendor/bin/php-cs-fixer fix" } diff --git a/phpstan.neon b/phpstan.neon index 476d869c..c3d08d4a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,9 +5,10 @@ includes: - vendor/phpstan/phpstan-webmozart-assert/extension.neon parameters: + level: 5 paths: - . - excludes_analyse: + excludePaths: - %currentWorkingDirectory%/DependencyInjection/Configuration.php - %currentWorkingDirectory%/EventSubscriber/AutoLoginSubscriber.php - %currentWorkingDirectory%/Middleware/EventMiddleware.php diff --git a/phpunit-9.xml.dist b/phpunit-9.xml.dist new file mode 100644 index 00000000..44992513 --- /dev/null +++ b/phpunit-9.xml.dist @@ -0,0 +1,23 @@ + + + + + + Tests/ + + + + + + ./ + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 44992513..50f90114 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,18 +6,24 @@ bootstrap="Tests/bootstrap.php" > - - Tests/ + + ./Tests - - - ./ - - - + + + + + ./ + + + Resources/ + Tests/ + vendor/ + +