From cdae2cf8f80dcac848d4befb36e34c46a00e42d9 Mon Sep 17 00:00:00 2001 From: George Younger Date: Mon, 27 Nov 2023 14:07:50 +0100 Subject: [PATCH] Add Symfony 6.x support (#15) * Add support for Symfony 6.3 * Revert backward compatibility * SUPPORT-85540 - add symfony 6 support * SUPPORT-85540 - fixed PR comments * SUPPORT-85540 - fixed PR comments * Update phpunit.xml.dist Co-authored-by: Boril Yordanov * Update phpunit.xml.dist Co-authored-by: Boril Yordanov --------- Co-authored-by: Nikolay Haralambiev Co-authored-by: Yuri Gaidoba Co-authored-by: Boril Yordanov --- .gitignore | 2 ++ CHANGELOG.md | 11 ++++++++ composer.json | 10 ++++--- phpunit.xml.dist | 27 +++++++------------ .../Service/Doctrine/DoctrineTestCase.php | 12 ++++----- .../Service/Doctrine/ResultIteratorTest.php | 2 +- .../Service/Doctrine/ResultProviderTest.php | 17 ++++++++---- .../Service/Doctrine/QueryAnalyserTest.php | 5 ++-- 8 files changed, 49 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index d4485de..80873ba 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ build/ phpunit.xml composer.lock bin/ + +.phpunit.result.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f2b370..59d53ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.4.0 +### Added +- Added support for `Symfony 6.x` + +### Changed +- Bumped `PHP` to `^7.1` +- Bumped `doctrine/orm` to `^2.5` + +### Removed +- Removed support for `Symfony 2` + ## 1.3.0 ### Added - Support for PHP 8. diff --git a/composer.json b/composer.json index eeec94e..9586190 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,16 @@ } }, "require": { - "php": ">=7.0|>=8.0", - "doctrine/orm": "^2.0", + "php": "^7.1|^8.0", + "doctrine/orm": "^2.5", "psr/log": "^1.0|^2.0", - "symfony/property-access": "^2.8|^3.0|^4.0|^5.0", + "symfony/property-access": "^3.0|^4.0|^5.0|^6.0", "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "^6.0|^9.0" + "doctrine/annotations": "^1.0 || ^2.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "symfony/cache": "^3.0|^4.0|^5.0|^6.0" }, "config": { "bin-dir": "bin" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b37c48d..9f26824 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,18 @@ - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" + bootstrap="vendor/autoload.php"> + + + + ./src + + tests - - - - ./src - - diff --git a/tests/Functional/Service/Doctrine/DoctrineTestCase.php b/tests/Functional/Service/Doctrine/DoctrineTestCase.php index f8b278b..c3e040a 100644 --- a/tests/Functional/Service/Doctrine/DoctrineTestCase.php +++ b/tests/Functional/Service/Doctrine/DoctrineTestCase.php @@ -4,8 +4,6 @@ namespace Paysera\Pagination\Tests\Functional\Service\Doctrine; use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\Annotations\AnnotationRegistry; -use Doctrine\Common\Cache\ArrayCache; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Tools\SchemaTool; @@ -14,10 +12,11 @@ use Paysera\Pagination\Tests\Functional\Fixtures\ParentTestEntity; use PHPUnit\Framework\TestCase; use Doctrine\ORM\Configuration; +use Symfony\Component\Cache\Adapter\ArrayAdapter; abstract class DoctrineTestCase extends TestCase { - protected function createTestEntityManager() + protected function createTestEntityManager(): EntityManager { if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Extension pdo_sqlite is required.'); @@ -40,7 +39,7 @@ protected function createTestEntityManager() return $entityManager; } - protected function createTestConfiguration() + protected function createTestConfiguration(): Configuration { $config = new Configuration(); $config->setEntityNamespaces(['PaginationTest' => 'Paysera\Pagination\Tests\Functional\Fixtures']); @@ -48,9 +47,8 @@ protected function createTestConfiguration() $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace('PaginationTest\Doctrine'); $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader())); - $config->setQueryCacheImpl(new ArrayCache()); - $config->setMetadataCacheImpl(new ArrayCache()); - AnnotationRegistry::registerLoader('class_exists'); + $config->setQueryCache(new ArrayAdapter()); + $config->setMetadataCache(new ArrayAdapter()); return $config; } diff --git a/tests/Functional/Service/Doctrine/ResultIteratorTest.php b/tests/Functional/Service/Doctrine/ResultIteratorTest.php index dbf1306..3c86935 100644 --- a/tests/Functional/Service/Doctrine/ResultIteratorTest.php +++ b/tests/Functional/Service/Doctrine/ResultIteratorTest.php @@ -29,7 +29,7 @@ class ResultIteratorTest extends DoctrineTestCase */ private $logger; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/Functional/Service/Doctrine/ResultProviderTest.php b/tests/Functional/Service/Doctrine/ResultProviderTest.php index ce322f6..fc674d1 100644 --- a/tests/Functional/Service/Doctrine/ResultProviderTest.php +++ b/tests/Functional/Service/Doctrine/ResultProviderTest.php @@ -4,7 +4,13 @@ namespace Paysera\Pagination\Tests\Functional\Service\Doctrine; use DateTime; +use Doctrine\DBAL\Exception; +use Doctrine\ORM\Exception\MissingMappingDriverImplementation; +use Doctrine\ORM\Exception\ORMException; +use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\Tools\ToolsException; +use Doctrine\Persistence\Mapping\MappingException; use Paysera\Pagination\Entity\OrderingConfiguration; use Doctrine\ORM\EntityManager; use Paysera\Pagination\Exception\InvalidGroupByException; @@ -20,6 +26,7 @@ use Paysera\Pagination\Tests\Functional\Fixtures\ChildTestEntity; use Paysera\Pagination\Tests\Functional\Fixtures\DateTimeEntity; use Paysera\Pagination\Tests\Functional\Fixtures\ParentTestEntity; +use ReflectionException; use Symfony\Component\PropertyAccess\PropertyAccess; class ResultProviderTest extends DoctrineTestCase @@ -29,7 +36,7 @@ class ResultProviderTest extends DoctrineTestCase */ private $resultProvider; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -146,7 +153,7 @@ public function testGetResultForQuery(Result $expectedResult, Pager $pager, $tot $this->assertEquals($expectedResult, $result); } - public function getResultProvider() + public function getResultProvider(): array { return [ 'default' => [ @@ -403,7 +410,7 @@ private function createHierarchicalData(EntityManager $entityManager) $entityManager->flush(); } - public function getResultProviderForSeveralLevelOrdering() + public function getResultProviderForSeveralLevelOrdering(): array { return [ 'name asc, parent_name asc, id asc' => [ @@ -559,7 +566,7 @@ private function createDateTimeRelatedData(EntityManager $entityManager) $entityManager->flush(); } - public function getResultProviderForDateTimeField() + public function getResultProviderForDateTimeField(): array { return [ 'first page' => [ @@ -748,7 +755,7 @@ public function testGetTotalCountForQueryGetsCorrectCountWhenNoNullsAreInResult( $this->assertSame(30, $this->resultProvider->getTotalCountForQuery($configuredQuery)); } - public function getResultProviderForGetTotalCountForQuery() + public function getResultProviderForGetTotalCountForQuery(): array { $entityManager = $this->createTestEntityManager(); $this->createTestData($entityManager); diff --git a/tests/Unit/Service/Doctrine/QueryAnalyserTest.php b/tests/Unit/Service/Doctrine/QueryAnalyserTest.php index ee71588..d2f1dca 100644 --- a/tests/Unit/Service/Doctrine/QueryAnalyserTest.php +++ b/tests/Unit/Service/Doctrine/QueryAnalyserTest.php @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; +use InvalidArgumentException; use Paysera\Pagination\Entity\Doctrine\ConfiguredQuery; use Paysera\Pagination\Entity\Pager; use Paysera\Pagination\Service\Doctrine\QueryAnalyser; @@ -15,11 +16,11 @@ class QueryAnalyserTest extends TestCase { /** * @dataProvider providerForInvalidData - * @expectedException \InvalidArgumentException * @param QueryBuilder $queryBuilder */ public function testAnalyseQueryWithInvalidData(QueryBuilder $queryBuilder) { + $this->expectException(InvalidArgumentException::class); $analyser = new QueryAnalyser(); $configuredQuery = new ConfiguredQuery($queryBuilder); @@ -28,7 +29,7 @@ public function testAnalyseQueryWithInvalidData(QueryBuilder $queryBuilder) $analyser->analyseQuery($configuredQuery, $pager); } - public function providerForInvalidData() + public function providerForInvalidData(): array { return [ 'Without select part' => [