Skip to content

Commit

Permalink
Upgrade PHPUnit and add PHP 8.4 to CI (#134)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alexander-schranz authored Jul 25, 2024
1 parent ca49c52 commit fbd753e
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 57 deletions.
24 changes: 0 additions & 24 deletions .env.dist

This file was deleted.

65 changes: 57 additions & 8 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,27 @@ jobs:
runs-on: ubuntu-latest

env:
DATABASE_URL: mysql://root:[email protected]:3306/sulu_test?serverVersion=5.7
DATABASE_URL: mysql://root:[email protected]: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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:[email protected]: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
8 changes: 8 additions & 0 deletions Tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion Tests/Application/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ services:

sulu_media.storage:
class: Sulu\Bundle\SyliusConsumerBundle\Tests\Functional\Mocks\Storage
public: true
public: true
2 changes: 2 additions & 0 deletions Tests/Functional/Adapter/ImageMediaAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +34,7 @@

class ImageMediaAdapterTest extends KernelTestCase
{
use ProphecyTrait;
use PurgeDatabaseTrait;

/**
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Entity/ImageMediaBridgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Entity/TaxonCategoryBridgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Handler/RemoveProductMessageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Handler/RemoveProductVariantMessageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Handler/RemoveTaxonMessageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Handler/SynchronizeImageMessageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

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;
use Sulu\Bundle\SyliusConsumerBundle\Payload\ImagePayload;

class SynchronizeImageMessageHandlerTest extends TestCase
{
use ProphecyTrait;

public function testInvoke(): void
{
$adapter1 = $this->prophesize(ImageAdapterInterface::class);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Handler/SynchronizeProductMessageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

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;
use Sulu\Bundle\SyliusConsumerBundle\Payload\ProductPayload;

class SynchronizeProductMessageHandlerTest extends TestCase
{
use ProphecyTrait;

public function testInvoke(): void
{
$adapter1 = $this->prophesize(ProductAdapterInterface::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

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;
use Sulu\Bundle\SyliusConsumerBundle\Payload\ProductVariantPayload;

class SynchronizeProductVariantMessageHandlerTest extends TestCase
{
use ProphecyTrait;

public function testInvoke(): void
{
$adapter1 = $this->prophesize(ProductVariantAdapterInterface::class);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Handler/SynchronizeTaxonsMessageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

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;
use Sulu\Bundle\SyliusConsumerBundle\Payload\TaxonPayload;

class SynchronizeTaxonsMessageHandlerTest extends TestCase
{
use ProphecyTrait;

public function testInvoke(): void
{
$adapter1 = $this->prophesize(TaxonAdapterInterface::class);
Expand Down
32 changes: 17 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
}
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit fbd753e

Please sign in to comment.