Skip to content

Commit

Permalink
Upgrade PHPUnit and add PHP 8.4 to CI (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored Jul 24, 2024
1 parent f5db9a5 commit 91b7157
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 30 deletions.
33 changes: 24 additions & 9 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]/sulu_form_test?serverVersion=12.5
Expand All @@ -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:[email protected]/sulu_form_test?serverVersion=5.7
Expand Down Expand Up @@ -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:[email protected]/sulu_form_test?serverVersion=12.5
DATABASE_CHARSET: UTF8
DATABASE_COLLATE:

- php-version: '8.3'
database: mysql
dependency-versions: 'highest'
tools: 'composer:v2'
Expand All @@ -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:[email protected]/sulu_form_test?serverVersion=5.7
Expand All @@ -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
Expand All @@ -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 }}
Expand All @@ -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:
Expand All @@ -131,18 +146,18 @@ jobs:

steps:
- name: Checkout project
uses: actions/checkout@v2
uses: actions/checkout@v4

- 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

- 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 }}
Expand Down
4 changes: 1 addition & 3 deletions Command/FormGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

class FormGeneratorCommand extends Command
{
protected static $defaultName = 'sulu:form:generate-form';

/**
* @var EntityManagerInterface
*/
Expand All @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/Application/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
2 changes: 0 additions & 2 deletions Tests/Functional/Mail/HelperTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Metadata/DynamicFormMetadataLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Configuration/FormConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,8 @@
*/
class FormConfigurationFactoryTest extends TestCase
{
use ProphecyTrait;

public function testBuildByDynamic(): void
{
$dynamic = $this->createDynamic();
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Event/ProtectedMediaSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,8 @@

class ProtectedMediaSubscriberTest extends TestCase
{
use ProphecyTrait;

/**
* @var EntityManagerInterface|ObjectProphecy
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Event/SendinblueListSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +34,8 @@

class SendinblueListSubscriberTest extends TestCase
{
use ProphecyTrait;

/**
* @var RequestStack
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Mail/MailerHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,8 @@
*/
class MailerHelperTest extends TestCase
{
use ProphecyTrait;

/**
* @var MailerHelper
*/
Expand Down
19 changes: 19 additions & 0 deletions Tests/prophecy-trait-bc-layer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Prophecy\PhpUnit;

/**
* @internal
*/
trait ProphecyTrait
{
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@
"massive/search-bundle": "^2.0",
"php-cs-fixer/shim": "^3.0",
"phpspec/prophecy": "^1.14",
"phpspec/prophecy-phpunit": "^1.0 || ^2.0",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-doctrine": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^8.0",
"phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^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",
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ parameters:
- %currentWorkingDirectory%/vendor/*
- %currentWorkingDirectory%/Tests/*
- %currentWorkingDirectory%/DependencyInjection/Configuration.php
- %currentWorkingDirectory%/Tests/prophecy-trait-bc-layer.php
symfony:
container_xml_path: %rootDir%/../../../Tests/Application/var/cache/admin/dev/Sulu_Bundle_FormBundle_Tests_Application_KernelDevDebugContainer.xml
console_application_loader: Tests/phpstan/console-application.php
Expand Down
24 changes: 24 additions & 0 deletions phpunit-9.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="Tests/test-bootstrap.php">
<testsuites>
<testsuite name="Sulu Form Bundle">
<directory>./Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory>.</directory>
<exclude>
<directory>Resources/</directory>
<directory>Tests/</directory>
<directory>vendor/</directory>
</exclude>
</whitelist>
</filter>

<php>
<env name="KERNEL_CLASS" value="Sulu\Bundle\FormBundle\Tests\Application\Kernel"/>
<env name="APP_ENV" value="test" force="true"/>
</php>
</phpunit>
25 changes: 12 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="Tests/test-bootstrap.php">
<testsuites>
<testsuites>
<testsuite name="Sulu Form Bundle">
<directory>./Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory>.</directory>
<exclude>
<directory>Resources/</directory>
<directory>Tests/</directory>
<directory>vendor/</directory>
</exclude>
</whitelist>
</filter>

<php>
<env name="KERNEL_CLASS" value="Sulu\Bundle\FormBundle\Tests\Application\Kernel"/>
<env name="APP_ENV" value="test" force="true"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>

<source>
<include>
<directory>./</directory>
</include>
<exclude>
<directory>Resources/</directory>
<directory>Tests/</directory>
<directory>vendor/</directory>
</exclude>
</source>
</phpunit>

0 comments on commit 91b7157

Please sign in to comment.