Skip to content

Commit

Permalink
chore: remove support of PHP 7.4 and 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre committed Mar 10, 2024
1 parent d517a8f commit 96cb584
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 162 deletions.
20 changes: 4 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ jobs:
strategy:
fail-fast: false
matrix:
# Symfony 5.4 requires PHP >= 7.2, it will be installed on PHP 7.4
# Symfony 6.4 requires PHP >= 8.0, it will be installed on PHP >= 8.0
# Symfony 7.0 requires PHP >= 8.2, it will be installed on PHP >= 8.2
php-version: ['8.2']
php-version: ['']
composer-flags: ['']
symfony-version: ['']
mysql-client: [ "default-mysql-client" ]
include:
- php-version: 7.4
- php-version: 8.1
# Use "update" instead of "install" since it allows using the "--prefer-lowest" option
composer-flags: "update --prefer-lowest"
- php-version: 7.4
# add a specific job to test 5.4 for all Symfony packages
symfony-version: "^5.4"
- php-version: 8.1
# add a specific job to test ^5.4 for all Symfony packages
symfony-version: "^5.4"
Expand All @@ -34,7 +28,6 @@ jobs:
- php-version: 8.2
# add a specific job to test ^6.4 for all Symfony packages
symfony-version: "^6.4"
- php-version: 8.2
- php-version: 8.2
symfony-version: "^7.0"
- php-version: 8.3
Expand Down Expand Up @@ -107,10 +100,6 @@ jobs:
composer config extra.symfony.require "${{ matrix.symfony-version }}"
composer require --no-update symfony/framework-bundle=${{ matrix.symfony-version }}
# This is needed to fix builds on Symfony 5.4 where the `annotation_reader` service may not be set up if the Annotations package is not in the production dependencies
- name: Move Annotations to require
run: composer require --no-update "doctrine/annotations:^1.8.0|^2.0"

- name: Install Composer dependencies
if: matrix.composer-flags == ''
run: composer install
Expand All @@ -126,8 +115,7 @@ jobs:
run: echo '127.0.0.1 mariadb postgres mongodb' | sudo tee -a /etc/hosts

- name: Run tests
# In phpunit.xml.dist, tests annotated with "@group mysql" are excluded, revert this
# Run tests twice to ensure that tests are idempotent even if database caching is enabled
run: |
php ./vendor/bin/phpunit --testdox --exclude-group ""
php ./vendor/bin/phpunit --testdox --exclude-group ""
php ./vendor/bin/phpunit --testdox
php ./vendor/bin/phpunit --testdox
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.3-fpm
FROM php:8.1-fpm
WORKDIR "/application"

RUN apt-get update \
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"doctrine/common": "^2.13 || ^3.0",
"doctrine/persistence": "^1.3.3 || ^2.0 || ^3.0",
"symfony/deprecation-contracts": "^2.1 || ^3.0",
Expand All @@ -25,14 +25,13 @@
"symfony/yaml": "^5.4 || ^6.3 || ^7.0"
},
"require-dev": {
"doctrine/annotations": "^1.8.0 || ^2.0",
"doctrine/data-fixtures": "^1.7",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/doctrine-fixtures-bundle": "^3.5.1 || ^4.0",
"doctrine/mongodb-odm-bundle": "^4.2 || ^5.0",
"doctrine/orm": "^2.7",
"monolog/monolog": "^1.25.1 || ^2.0 || ^3.0",
"phpunit/phpunit": "^9.6.17 || ^10.5.11 || ^11.0.4",
"phpunit/phpunit": "^10.5.11 || ^11.0.4",
"symfony/doctrine-bridge": "^5.4 || ^6.3 || ^7.0",
"symfony/monolog-bridge": "^5.4 || ^6.3 || ^7.0",
"symfony/monolog-bundle": "^3.2",
Expand Down
16 changes: 15 additions & 1 deletion doc/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,24 @@ Install the dependencies with composer:
docker-compose exec php-fpm composer install
```

Install the lowest dependencies with composer:

```bash
docker-compose exec php-fpm composer update --prefer-lowest
```

Now you can execute the tests with the following command:

```bash
docker-compose exec php-fpm ./vendor/bin/phpunit --exclude-group ""
docker-compose exec php-fpm ./vendor/bin/phpunit
```

## Delete the cache

If you change the version of PHP or dependencies, the caches may cause issues, they can be deleted:

```bash
docker-compose exec php-fpm bash -c "rm -rf tests/App*/var/cache/*"
```

## Apply changes suggested by PHP-CS-Fixer
Expand Down
7 changes: 0 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@
<directory>tests/Test</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>mysql</group>
<group>pgsql</group>
</exclude>
</groups>
</phpunit>
9 changes: 2 additions & 7 deletions src/Services/DatabaseToolCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Liip\TestFixturesBundle\Services;

use Doctrine\Common\Annotations\Reader;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -25,21 +24,17 @@ final class DatabaseToolCollection
{
private ContainerInterface $container;

/** @var Reader|null */
private $annotationReader;

/**
* @var AbstractDatabaseTool[][]
*/
private array $items = [];

public function __construct(ContainerInterface $container, ?Reader $annotationReader = null)
public function __construct(ContainerInterface $container, mixed $annotationReader = null)
{
$this->container = $container;
$this->annotationReader = $annotationReader;

if (null !== $annotationReader) {
trigger_deprecation('liip/test-fixtures-bundle', '2.5', 'Passing a "%s" to the "%s" constructor is deprecated.', Reader::class, self::class);
throw new \RuntimeException(sprintf('Passing a second argument to the "%s" constructor is not supported since liip/test-fixtures-bundle 3.0.', self::class));
}
}

Expand Down
24 changes: 0 additions & 24 deletions tests/App/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,24 @@
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*
* @ORM\Table(name="liip_user")
*/
#[ORM\Entity]
#[ORM\Table(name: 'liip_user')]
class User
{
/**
* @ORM\Id
*
* @ORM\Column(type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;

/**
* @ORM\Column
*/
#[ORM\Column]
private string $name;

/**
* @ORM\Column
*/
#[ORM\Column]
private string $salt;

/**
* @ORM\Column
*/
#[ORM\Column]
private string $email;

/**
* @ORM\Column(nullable=true)
*/
#[ORM\Column(nullable: true)]
private ?string $dummyText = null;

Expand Down
34 changes: 14 additions & 20 deletions tests/Test/ConfigEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@

namespace Liip\Acme\Tests\Test;

use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Liip\Acme\Tests\AppConfigEvents\AppConfigEventsKernel;
use Liip\Acme\Tests\AppConfigEvents\EventListener\FixturesSubscriber;
use Liip\Acme\Tests\Traits\ContainerProvider;
use Liip\TestFixturesBundle\LiipTestFixturesEvents;
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
Expand All @@ -30,14 +32,10 @@
* Tests/App/AppKernel.php.
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("dataProvider")
*
* @internal
*/
#[RunTestsInSeparateProcesses]
#[PreserveGlobalState(false)]
class ConfigEventsTest extends KernelTestCase
{
use ContainerProvider;
Expand Down Expand Up @@ -88,10 +86,9 @@ public function testLoadEmptyFixturesAndCheckEvents(): void
* Check that events are called.
*
* We disable the cache to ensure that all the code is executed.
*
* @dataProvider fixturesEventsProvider
*/
public function testLoadEmptyFixturesAndCheckEventsAreCalled(string $eventName, string $methodName, int $numberOfInvocations, bool $withCache = true): void
#[DataProvider('fixturesEventsProvider')]
public function testLoadEmptyFixturesAndCheckEventsAreCalled(string $eventName, string $methodName, int $numberOfInvocations, ?bool $withCache = true): void
{
/** @var AbstractDatabaseTool $databaseTool */
$databaseTool = $this->getTestContainer()->get(DatabaseToolCollection::class)->get();
Expand Down Expand Up @@ -127,9 +124,8 @@ public function testLoadEmptyFixturesAndCheckEventsAreCalled(string $eventName,

/**
* We disable the cache to ensure that other events are called.
*
* @dataProvider fixturesEventsProvider
*/
#[DataProvider('fixturesEventsProvider')]
public function testLoadEmptyFixturesAndCheckEventsAreCalledWithoutCache(string $eventName, string $methodName, int $numberOfInvocations): void
{
// Swap 0 → 1 and 1 → 0
Expand All @@ -138,15 +134,13 @@ public function testLoadEmptyFixturesAndCheckEventsAreCalledWithoutCache(string
$this->testLoadEmptyFixturesAndCheckEventsAreCalled($eventName, $methodName, $numberOfInvocations, false);
}

public static function fixturesEventsProvider(): array
public static function fixturesEventsProvider(): iterable
{
return [
[LiipTestFixturesEvents::PRE_FIXTURE_BACKUP_RESTORE, 'preFixtureBackupRestore', 1],
[LiipTestFixturesEvents::POST_FIXTURE_SETUP, 'postFixtureSetup', 0],
[LiipTestFixturesEvents::POST_FIXTURE_BACKUP_RESTORE, 'postFixtureBackupRestore', 1],
[LiipTestFixturesEvents::PRE_REFERENCE_SAVE, 'preReferenceSave', 0],
[LiipTestFixturesEvents::POST_REFERENCE_SAVE, 'postReferenceSave', 0],
];
yield 'preFixtureBackupRestore' => [LiipTestFixturesEvents::PRE_FIXTURE_BACKUP_RESTORE, 'preFixtureBackupRestore', 1];
yield 'postFixtureSetup' => [LiipTestFixturesEvents::POST_FIXTURE_SETUP, 'postFixtureSetup', 0];
yield 'postFixtureBackupRestore' => [LiipTestFixturesEvents::POST_FIXTURE_BACKUP_RESTORE, 'postFixtureBackupRestore', 1];
yield 'preReferenceSave' => [LiipTestFixturesEvents::PRE_REFERENCE_SAVE, 'preReferenceSave', 0];
yield 'postReferenceSave' => [LiipTestFixturesEvents::POST_REFERENCE_SAVE, 'postReferenceSave', 0];
}

protected static function getKernelClass(): string
Expand Down
13 changes: 6 additions & 7 deletions tests/Test/ConfigMongodbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

namespace Liip\Acme\Tests\Test;

/*
* This file is part of the Liip/TestFixturesBundle
*
Expand All @@ -21,6 +23,8 @@
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\MongoDBDatabaseTool;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
Expand All @@ -30,12 +34,10 @@
* Tests/App/AppKernel.php.
* So it must be loaded in a separate process.
*
* @#runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @internal
*/
#[RunTestsInSeparateProcesses]
#[PreserveGlobalState(false)]
class ConfigMongodbTest extends KernelTestCase
{
use ContainerProvider;
Expand All @@ -50,9 +52,6 @@ protected function setUp(): void
if (!class_exists(DoctrineMongoDBBundle::class)) {
$this->markTestSkipped('Need doctrine/mongodb-odm-bundle package.');
}
if (version_compare(\PHP_VERSION, '8.1.0') < 0) {
$this->markTestSkipped('MongoDB Tests doesn\'t support Outdated PHP Version. <8.1.0');
}

parent::setUp();

Expand Down
10 changes: 1 addition & 9 deletions tests/Test/ConfigMysqlCacheDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace Liip\Acme\Tests\Test;

use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Liip\Acme\Tests\App\Entity\User;
use Liip\Acme\Tests\AppConfigMysqlCacheDb\AppConfigMysqlKernelCacheDb;
use PHPUnit\Framework\Attributes\Group;

/**
* Test MySQL database with database caching enabled.
Expand All @@ -35,15 +35,10 @@
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("group")
*
* @internal
*/
class ConfigMysqlCacheDbTest extends ConfigMysqlTest
{
/**
* @group mysql
*/
public function testLoadFixturesAndCheckBackup(): void
{
$this->assertTrue($this->databaseTool->isDatabaseCacheEnabled());
Expand Down Expand Up @@ -114,9 +109,6 @@ public function testLoadFixturesAndCheckBackup(): void
);
}

/**
* @group mysql
*/
public function testLoadFixturesCheckReferences(): void
{
$this->markTestSkipped('This test is broken right now.');
Expand Down
11 changes: 4 additions & 7 deletions tests/Test/ConfigMysqlKeepDatabaseAndSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

namespace Liip\Acme\Tests\Test;

use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Liip\Acme\Tests\AppConfigMysqlKeepDatabaseAndSchema\AppConfigMysqlKernelKeepDatabaseAndSchema;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
* Test MySQL database with database caching enabled.
Expand All @@ -30,14 +31,10 @@
* Tests/App/AppKernel.php.
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("group")
*
* @internal
*/
#[RunTestsInSeparateProcesses]
#[PreserveGlobalState(false)]
class ConfigMysqlKeepDatabaseAndSchemaTest extends ConfigMysqlTest
{
protected static function getKernelClass(): string
Expand Down
Loading

0 comments on commit 96cb584

Please sign in to comment.