From 64031e307ff9820cc19c1ba1d6a5b5ef290ba3e5 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 24 Jul 2024 18:32:50 +0200 Subject: [PATCH 1/4] Upgrade PHPUnit and add PHP 8.4 to CI --- .github/workflows/test-application.yaml | 31 ++++++++++++++++++------ Tests/Functional/Mail/HelperTestCase.php | 2 -- composer.json | 2 +- phpunit-9.xml.dist | 24 ++++++++++++++++++ phpunit.xml.dist | 25 +++++++++---------- 5 files changed, 60 insertions(+), 24 deletions(-) create mode 100644 phpunit-9.xml.dist diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 64ab2b95..c7022446 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -20,6 +20,7 @@ jobs: database: postgres dependency-versions: 'lowest' tools: 'composer:v2' + phpunit-config: 'phpunit-9.xml.dist' env: SYMFONY_DEPRECATIONS_HELPER: disabled DATABASE_URL: postgres://postgres:postgres@127.0.0.1/sulu_form_test?serverVersion=12.5 @@ -30,6 +31,7 @@ jobs: database: mysql dependency-versions: 'highest' tools: 'composer:v2' + phpunit-config: 'phpunit-9.xml.dist' env: SYMFONY_DEPRECATIONS_HELPER: weak DATABASE_URL: mysql://root:root@127.0.0.1/sulu_form_test?serverVersion=5.7 @@ -57,6 +59,16 @@ jobs: DATABASE_COLLATE: utf8mb4_unicode_ci - php-version: '8.2' + database: postgres + dependency-versions: 'highest' + tools: 'composer:v2' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + DATABASE_URL: postgres://postgres:postgres@127.0.0.1/sulu_form_test?serverVersion=12.5 + DATABASE_CHARSET: UTF8 + DATABASE_COLLATE: + + - php-version: '8.3' database: mysql dependency-versions: 'highest' tools: 'composer:v2' @@ -66,10 +78,11 @@ jobs: DATABASE_CHARSET: utf8mb4 DATABASE_COLLATE: utf8mb4_unicode_ci - - php-version: '8.3' + - php-version: '8.4' database: mysql dependency-versions: 'highest' tools: 'composer:v2' + composer-options: '--ignore-platform-reqs' env: SYMFONY_DEPRECATIONS_HELPER: weak DATABASE_URL: mysql://root:root@127.0.0.1/sulu_form_test?serverVersion=5.7 @@ -96,7 +109,7 @@ jobs: steps: - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -106,11 +119,13 @@ jobs: tools: ${{ matrix.tools }} coverage: none - - name: Remove not required tooling for tests - run: composer remove php-cs-fixer/shim "*phpstan*" --dev --no-update + - 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@v1 + uses: ramsey/composer-install@v2 with: dependency-versions: ${{matrix.dependency-versions}} composer-options: ${{ matrix.composer-options }} @@ -120,7 +135,7 @@ jobs: 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: @@ -131,7 +146,7 @@ jobs: steps: - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -142,7 +157,7 @@ jobs: coverage: none - name: Install composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: dependency-versions: ${{matrix.dependency-versions}} composer-options: ${{ matrix.composer-options }} diff --git a/Tests/Functional/Mail/HelperTestCase.php b/Tests/Functional/Mail/HelperTestCase.php index 84da9504..a6ab71f6 100644 --- a/Tests/Functional/Mail/HelperTestCase.php +++ b/Tests/Functional/Mail/HelperTestCase.php @@ -33,8 +33,6 @@ class HelperTestCase extends SuluTestCase protected function setUp(): void { - static::$kernel = null; // requires as Symfony 4.4 does not unset on tearDown - $this->client = $this->createWebsiteClient(); $this->purgeDatabase(); $this->initPhpcr(); diff --git a/composer.json b/composer.json index edff35e5..a61ef1b7 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "phpstan/phpstan-doctrine": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-symfony": "^1.0", - "phpunit/phpunit": "^8.0", + "phpunit/phpunit": "^9.6 || ^10.0", "sendinblue/api-v3-sdk": "^8.0", "symfony/browser-kit": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/dotenv": "^4.4 || ^5.0 || ^6.0 || ^7.0", diff --git a/phpunit-9.xml.dist b/phpunit-9.xml.dist new file mode 100644 index 00000000..0e62f3be --- /dev/null +++ b/phpunit-9.xml.dist @@ -0,0 +1,24 @@ + + + + + ./Tests + + + + + + . + + Resources/ + Tests/ + vendor/ + + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bbaf9804..f355e585 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,25 +1,24 @@ - + ./Tests - - - . - - Resources/ - Tests/ - vendor/ - - - - - + + + + ./ + + + Resources/ + Tests/ + vendor/ + + From dbce239110f7c73dfd495f29dafb52551ffe5184 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 24 Jul 2024 18:41:37 +0200 Subject: [PATCH 2/4] Handle Prophesize Trait --- Tests/Application/config/bootstrap.php | 4 ++++ .../FormConfigurationFactoryTest.php | 3 +++ .../Event/ProtectedMediaSubscriberTest.php | 3 +++ .../Event/SendinblueListSubscriberTest.php | 3 +++ Tests/Unit/Mail/MailerHelperTest.php | 3 +++ Tests/prophecy-trait-bc-layer.php | 19 +++++++++++++++++++ composer.json | 3 ++- phpstan.neon | 1 + 8 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 Tests/prophecy-trait-bc-layer.php diff --git a/Tests/Application/config/bootstrap.php b/Tests/Application/config/bootstrap.php index 7314acf9..30707549 100644 --- a/Tests/Application/config/bootstrap.php +++ b/Tests/Application/config/bootstrap.php @@ -21,6 +21,10 @@ require $file; +if (!\trait_exists(Prophecy\PhpUnit\ProphecyTrait::class)) { // backwards compatibility layer for < PHP 7.3 + require __DIR__ . '/../../prophecy-trait-bc-layer.php'; +} + // Load cached env vars if the .env.local.php file exists // Run "composer dump-env prod" to create it (requires symfony/flex >=1.2) if (\is_array($env = @include \dirname(__DIR__) . '/.env.local.php')) { diff --git a/Tests/Unit/Configuration/FormConfigurationFactoryTest.php b/Tests/Unit/Configuration/FormConfigurationFactoryTest.php index ce791041..a1d62196 100644 --- a/Tests/Unit/Configuration/FormConfigurationFactoryTest.php +++ b/Tests/Unit/Configuration/FormConfigurationFactoryTest.php @@ -12,6 +12,7 @@ namespace Sulu\Bundle\FormBundle\Tests\Unit\Configuration; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Sulu\Bundle\FormBundle\Configuration\FormConfigurationFactory; use Sulu\Bundle\FormBundle\Configuration\MailConfigurationInterface; use Sulu\Bundle\FormBundle\Entity\Dynamic; @@ -26,6 +27,8 @@ */ class FormConfigurationFactoryTest extends TestCase { + use ProphecyTrait; + public function testBuildByDynamic(): void { $dynamic = $this->createDynamic(); diff --git a/Tests/Unit/Event/ProtectedMediaSubscriberTest.php b/Tests/Unit/Event/ProtectedMediaSubscriberTest.php index ca65f7ae..eb8ac205 100644 --- a/Tests/Unit/Event/ProtectedMediaSubscriberTest.php +++ b/Tests/Unit/Event/ProtectedMediaSubscriberTest.php @@ -15,6 +15,7 @@ use Doctrine\ORM\QueryBuilder; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\FormBundle\Event\ProtectedMediaSubscriber; use Sulu\Bundle\FormBundle\Tests\Application\Kernel; @@ -29,6 +30,8 @@ class ProtectedMediaSubscriberTest extends TestCase { + use ProphecyTrait; + /** * @var EntityManagerInterface|ObjectProphecy */ diff --git a/Tests/Unit/Event/SendinblueListSubscriberTest.php b/Tests/Unit/Event/SendinblueListSubscriberTest.php index 55aff833..77dfebd6 100644 --- a/Tests/Unit/Event/SendinblueListSubscriberTest.php +++ b/Tests/Unit/Event/SendinblueListSubscriberTest.php @@ -15,6 +15,7 @@ use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Message\RequestInterface; use Sulu\Bundle\FormBundle\Configuration\FormConfiguration; @@ -33,6 +34,8 @@ class SendinblueListSubscriberTest extends TestCase { + use ProphecyTrait; + /** * @var RequestStack */ diff --git a/Tests/Unit/Mail/MailerHelperTest.php b/Tests/Unit/Mail/MailerHelperTest.php index ae730026..54962a03 100644 --- a/Tests/Unit/Mail/MailerHelperTest.php +++ b/Tests/Unit/Mail/MailerHelperTest.php @@ -12,6 +12,7 @@ namespace Sulu\Bundle\FormBundle\Tests\Unit\Mail; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Psr\Log\LoggerInterface; use Sulu\Bundle\FormBundle\Mail\MailerHelper; @@ -27,6 +28,8 @@ */ class MailerHelperTest extends TestCase { + use ProphecyTrait; + /** * @var MailerHelper */ diff --git a/Tests/prophecy-trait-bc-layer.php b/Tests/prophecy-trait-bc-layer.php new file mode 100644 index 00000000..55757afb --- /dev/null +++ b/Tests/prophecy-trait-bc-layer.php @@ -0,0 +1,19 @@ + Date: Wed, 24 Jul 2024 18:45:45 +0200 Subject: [PATCH 3/4] Migrate to PHPUnit 10 --- .github/workflows/test-application.yaml | 2 +- Tests/Functional/Metadata/DynamicFormMetadataLoaderTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index c7022446..c8d8261d 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -151,7 +151,7 @@ jobs: - name: Install and configure PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 extensions: 'imagick' tools: 'composer:v2' coverage: none diff --git a/Tests/Functional/Metadata/DynamicFormMetadataLoaderTest.php b/Tests/Functional/Metadata/DynamicFormMetadataLoaderTest.php index 39f800f2..78e2b60d 100644 --- a/Tests/Functional/Metadata/DynamicFormMetadataLoaderTest.php +++ b/Tests/Functional/Metadata/DynamicFormMetadataLoaderTest.php @@ -238,8 +238,8 @@ public function testGetMetadataAttachmentEnglish(): void $this->assertEquals('number', $attachment->getItems()['options/max']->getType()); $this->assertEquals(6, $attachment->getItems()['options/max']->getColspan()); - $this->assertObjectHasAttribute('schema', $attachment); - $this->assertObjectHasAttribute('key', $attachment); + $this->assertTrue(\property_exists($attachment, 'schema')); + $this->assertTrue(\property_exists($attachment, 'key')); } public function testGetMetadataAttachmentGerman(): void From 014572e39589d779556677a9a0619d554fe6980e Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 24 Jul 2024 18:48:56 +0200 Subject: [PATCH 4/4] Update FormGeneratorCommand --- Command/FormGeneratorCommand.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Command/FormGeneratorCommand.php b/Command/FormGeneratorCommand.php index 924e3c81..92983ddf 100644 --- a/Command/FormGeneratorCommand.php +++ b/Command/FormGeneratorCommand.php @@ -22,8 +22,6 @@ class FormGeneratorCommand extends Command { - protected static $defaultName = 'sulu:form:generate-form'; - /** * @var EntityManagerInterface */ @@ -38,7 +36,7 @@ public function __construct( EntityManagerInterface $entityManager, WebspaceManagerInterface $webspaceManager ) { - parent::__construct(static::$defaultName); + parent::__construct('sulu:form:generate-form'); $this->entityManager = $entityManager; $this->webspaceManager = $webspaceManager; }