diff --git a/src/Datagrid/ProxyQuery.php b/src/Datagrid/ProxyQuery.php index cf266ea26..d1154ecd2 100644 --- a/src/Datagrid/ProxyQuery.php +++ b/src/Datagrid/ProxyQuery.php @@ -23,8 +23,6 @@ /** * This class try to unify the query usage with Doctrine. * - * @final since sonata-project/doctrine-orm-admin-bundle 3.x - * * @method Query\Expr expr() * @method QueryBuilder setCacheable($cacheable) * @method bool isCacheable() @@ -75,32 +73,32 @@ * @method QueryBuilder resetDQLParts($parts = null) * @method QueryBuilder resetDQLPart($part) */ -class ProxyQuery implements ProxyQueryInterface +final class ProxyQuery implements ProxyQueryInterface { /** * @var QueryBuilder */ - protected $queryBuilder; + private $queryBuilder; /** * @var string|null */ - protected $sortBy; + private $sortBy; /** * @var string|null */ - protected $sortOrder; + private $sortOrder; /** * @var int */ - protected $uniqueParameterId; + private $uniqueParameterId; /** * @var string[] */ - protected $entityJoinAliases; + private $entityJoinAliases; /** * For BC reasons, this property is true by default. @@ -142,7 +140,7 @@ public function __clone() * Optimize queries with a lot of rows. * It is not recommended to use "false" with left joins. */ - final public function setDistinct(bool $distinct): ProxyQueryInterface + public function setDistinct(bool $distinct): ProxyQueryInterface { if (!\is_bool($distinct)) { throw new \InvalidArgumentException('$distinct is not a boolean'); @@ -153,7 +151,7 @@ final public function setDistinct(bool $distinct): ProxyQueryInterface return $this; } - final public function isDistinct(): bool + public function isDistinct(): bool { return $this->distinct; } @@ -336,7 +334,7 @@ public function entityJoin(array $associationMappings): string * @see \Doctrine\ORM\Query::setHint * @see \Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER */ - final public function setHint(string $name, $value): ProxyQueryInterface + public function setHint(string $name, $value): ProxyQueryInterface { $this->hints[$name] = $value; @@ -347,7 +345,7 @@ final public function setHint(string $name, $value): ProxyQueryInterface * This method alters the query to return a clean set of object with a working * set of Object. */ - protected function getFixedQueryBuilder(QueryBuilder $queryBuilder): QueryBuilder + private function getFixedQueryBuilder(QueryBuilder $queryBuilder): QueryBuilder { $queryBuilderId = clone $queryBuilder; $rootAlias = current($queryBuilderId->getRootAliases()); diff --git a/src/Exporter/DataSource.php b/src/Exporter/DataSource.php index 882a92bed..03b904825 100644 --- a/src/Exporter/DataSource.php +++ b/src/Exporter/DataSource.php @@ -20,10 +20,7 @@ use Sonata\Exporter\Source\DoctrineORMQuerySourceIterator; use Sonata\Exporter\Source\SourceIteratorInterface; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.29 - */ -class DataSource implements DataSourceInterface +final class DataSource implements DataSourceInterface { public function createIterator(ProxyQueryInterface $query, array $fields): SourceIteratorInterface { diff --git a/src/Filter/DateTimeRangeFilter.php b/src/Filter/DateTimeRangeFilter.php index 5c5029a6a..26360d210 100644 --- a/src/Filter/DateTimeRangeFilter.php +++ b/src/Filter/DateTimeRangeFilter.php @@ -15,10 +15,7 @@ use Sonata\Form\Type\DateTimeRangeType; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.24 - */ -class DateTimeRangeFilter extends AbstractDateFilter +final class DateTimeRangeFilter extends AbstractDateFilter { /** * This Filter allows filtering by time. diff --git a/src/Filter/ModelAutocompleteFilter.php b/src/Filter/ModelAutocompleteFilter.php index 09a3efdd5..a8e9c4a1d 100644 --- a/src/Filter/ModelAutocompleteFilter.php +++ b/src/Filter/ModelAutocompleteFilter.php @@ -19,10 +19,7 @@ use Sonata\AdminBundle\Form\Type\Operator\EqualOperatorType; use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.24 - */ -class ModelAutocompleteFilter extends Filter +final class ModelAutocompleteFilter extends Filter { public function filter(ProxyQueryInterface $query, string $alias, string $field, array $data): void { diff --git a/src/Filter/ModelFilter.php b/src/Filter/ModelFilter.php index 2ccf34cce..4ae8ffcfe 100644 --- a/src/Filter/ModelFilter.php +++ b/src/Filter/ModelFilter.php @@ -20,10 +20,7 @@ use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.24 - */ -class ModelFilter extends Filter +final class ModelFilter extends Filter { public function filter(ProxyQueryInterface $query, string $alias, string $field, array $data): void { diff --git a/src/Filter/NumberFilter.php b/src/Filter/NumberFilter.php index 058191f1c..f2c8e344e 100644 --- a/src/Filter/NumberFilter.php +++ b/src/Filter/NumberFilter.php @@ -18,10 +18,7 @@ use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface; use Symfony\Component\Form\Extension\Core\Type\NumberType as FormNumberType; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.24 - */ -class NumberFilter extends Filter +final class NumberFilter extends Filter { public const CHOICES = [ NumberOperatorType::TYPE_EQUAL => '=', diff --git a/src/Filter/StringFilter.php b/src/Filter/StringFilter.php index 887a9c603..385222612 100644 --- a/src/Filter/StringFilter.php +++ b/src/Filter/StringFilter.php @@ -17,10 +17,7 @@ use Sonata\AdminBundle\Form\Type\Operator\StringOperatorType; use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.24 - */ -class StringFilter extends Filter +final class StringFilter extends Filter { public const TRIM_NONE = 0; public const TRIM_LEFT = 1; diff --git a/src/Filter/TimeFilter.php b/src/Filter/TimeFilter.php index a7fc3feeb..ffee060f0 100644 --- a/src/Filter/TimeFilter.php +++ b/src/Filter/TimeFilter.php @@ -15,10 +15,7 @@ use Symfony\Component\Form\Extension\Core\Type\TimeType; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.24 - */ -class TimeFilter extends AbstractDateFilter +final class TimeFilter extends AbstractDateFilter { /** * This filter has no range. diff --git a/src/Guesser/FilterTypeGuesser.php b/src/Guesser/FilterTypeGuesser.php index f2b803cfb..2ef6113ea 100644 --- a/src/Guesser/FilterTypeGuesser.php +++ b/src/Guesser/FilterTypeGuesser.php @@ -29,10 +29,7 @@ use Symfony\Component\Form\Guess\Guess; use Symfony\Component\Form\Guess\TypeGuess; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.24 - */ -class FilterTypeGuesser extends AbstractTypeGuesser +final class FilterTypeGuesser extends AbstractTypeGuesser { public function guessType(string $class, string $property, ModelManagerInterface $modelManager): ?TypeGuess { diff --git a/src/Guesser/TypeGuesser.php b/src/Guesser/TypeGuesser.php index e72bd5bed..88b11fb6d 100644 --- a/src/Guesser/TypeGuesser.php +++ b/src/Guesser/TypeGuesser.php @@ -19,10 +19,7 @@ use Symfony\Component\Form\Guess\Guess; use Symfony\Component\Form\Guess\TypeGuess; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.24 - */ -class TypeGuesser extends AbstractTypeGuesser +final class TypeGuesser extends AbstractTypeGuesser { public function guessType(string $class, string $property, ModelManagerInterface $modelManager): ?TypeGuess { diff --git a/src/Model/AuditReader.php b/src/Model/AuditReader.php index f571be511..d534eef54 100644 --- a/src/Model/AuditReader.php +++ b/src/Model/AuditReader.php @@ -16,15 +16,12 @@ use SimpleThings\EntityAudit\AuditReader as SimpleThingsAuditReader; use Sonata\AdminBundle\Model\AuditReaderInterface; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.24 - */ -class AuditReader implements AuditReaderInterface +final class AuditReader implements AuditReaderInterface { /** * @var SimpleThingsAuditReader */ - protected $auditReader; + private $auditReader; public function __construct(SimpleThingsAuditReader $auditReader) { diff --git a/src/Model/ModelManager.php b/src/Model/ModelManager.php index 70bce23a2..13d39cc47 100644 --- a/src/Model/ModelManager.php +++ b/src/Model/ModelManager.php @@ -20,7 +20,6 @@ use Doctrine\DBAL\Types\Type; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\OptimisticLockException; -use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\UnitOfWork; use Doctrine\Persistence\ManagerRegistry; @@ -33,16 +32,10 @@ use Sonata\AdminBundle\Model\LockInterface; use Sonata\AdminBundle\Model\ModelManagerInterface; use Sonata\DoctrineORMAdminBundle\Admin\FieldDescription; -use Sonata\DoctrineORMAdminBundle\Datagrid\OrderByToSelectWalker; use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; -use Sonata\Exporter\Source\DoctrineORMQuerySourceIterator; -use Sonata\Exporter\Source\SourceIteratorInterface; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; -/** - * @final since sonata-project/doctrine-orm-admin-bundle 3.24 - */ final class ModelManager implements ModelManagerInterface, LockInterface { public const ID_SEPARATOR = '~'; @@ -505,46 +498,6 @@ public function batchDelete(string $class, ProxyQueryInterface $query): void } } - /** - * NEXT_MAJOR: Remove this method. - * - * @deprecated since sonata-admin/doctrine-orm-admin-bundle 3.27 and will be removed in 4.0. - * - * @return DoctrineORMQuerySourceIterator - */ - public function getDataSourceIterator( - DatagridInterface $datagrid, - array $fields, - ?int $firstResult = null, - ?int $maxResult = null - ): SourceIteratorInterface { - @trigger_error(sprintf( - 'Method %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.27 and will be removed in 4.0.', - __METHOD__ - ), \E_USER_DEPRECATED); - - $datagrid->buildPager(); - $query = $datagrid->getQuery(); - - $query->select('DISTINCT '.current($query->getRootAliases())); - $query->setFirstResult($firstResult); - $query->setMaxResults($maxResult); - - if ($query instanceof ProxyQueryInterface) { - $sortBy = $query->getSortBy(); - - if (!empty($sortBy)) { - $query->addOrderBy($sortBy, $query->getSortOrder()); - $query = $query->getQuery(); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [OrderByToSelectWalker::class]); - } else { - $query = $query->getQuery(); - } - } - - return new DoctrineORMQuerySourceIterator($query, $fields); - } - public function getExportFields(string $class): array { $metadata = $this->getEntityManager($class)->getClassMetadata($class); diff --git a/tests/Datagrid/ProxyQueryTest.php b/tests/Datagrid/ProxyQueryTest.php index 02d144e0b..bb5c76771 100644 --- a/tests/Datagrid/ProxyQueryTest.php +++ b/tests/Datagrid/ProxyQueryTest.php @@ -162,11 +162,7 @@ public function testGetFixedQueryBuilder($class, $alias, $id, $expectedId, $valu ->method('getRootAliases') ->willReturn([$alias]); - $pq = $this->getMockBuilder(ProxyQuery::class) - ->setConstructorArgs([$qb]) - ->setMethods(['a']) - ->getMock(); - + $pq = new ProxyQuery($qb); $pq->setDistinct($distinct); /* Work */ diff --git a/tests/Exporter/DataSourceTest.php b/tests/Exporter/DataSourceTest.php index 9e133620b..fd87e111e 100644 --- a/tests/Exporter/DataSourceTest.php +++ b/tests/Exporter/DataSourceTest.php @@ -61,9 +61,7 @@ public function testSortableInDataSourceIterator( $em = $this->createStub(EntityManager::class); $em->method('getConfiguration')->willReturn($configuration); - $queryBuilder = $this->getMockBuilder(QueryBuilder::class) - ->setConstructorArgs([$em]) - ->getMock(); + $queryBuilder = $this->createMock(QueryBuilder::class); $queryBuilder->expects($isAddOrderBy ? $this->atLeastOnce() : $this->never())->method('addOrderBy'); $queryBuilder->method('getRootAliases')->willReturn(['a']); @@ -71,13 +69,13 @@ public function testSortableInDataSourceIterator( $query = new Query($em); $queryBuilder->method('getQuery')->willReturn($query); - $proxyQuery = $this->getMockBuilder(ProxyQuery::class) - ->setConstructorArgs([$queryBuilder]) - ->onlyMethods(['getSortBy', 'getSortOrder']) - ->getMock(); - - $proxyQuery->method('getSortOrder')->willReturn($sortOrder); - $proxyQuery->method('getSortBy')->willReturn($sortBy); + $proxyQuery = new ProxyQuery($queryBuilder); + if (null !== $sortBy) { + $proxyQuery->setSortBy([], ['fieldName' => $sortBy]); + } + if (null !== $sortOrder) { + $proxyQuery->setSortOrder($sortOrder); + } $this->dataSource->createIterator($proxyQuery, []); diff --git a/tests/Model/ModelManagerTest.php b/tests/Model/ModelManagerTest.php index 58975a4f6..f7d7b7856 100644 --- a/tests/Model/ModelManagerTest.php +++ b/tests/Model/ModelManagerTest.php @@ -18,23 +18,19 @@ use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Types\Type; -use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\OptimisticLockException; -use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ManagerRegistry; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Sonata\AdminBundle\Datagrid\DatagridInterface; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\Exception\LockException; use Sonata\AdminBundle\Exception\ModelManagerException; -use Sonata\DoctrineORMAdminBundle\Datagrid\OrderByToSelectWalker; use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; use Sonata\DoctrineORMAdminBundle\Model\ModelManager; use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\DoctrineType\ProductIdType; @@ -152,7 +148,7 @@ public function testSupportsQuery(bool $expected, object $object): void public function supportsQueryDataProvider(): iterable { - yield [true, $this->createMock(ProxyQuery::class)]; + yield [true, new ProxyQuery($this->createMock(QueryBuilder::class))]; yield [true, $this->createMock(QueryBuilder::class)]; yield [false, new \stdClass()]; } @@ -566,90 +562,6 @@ public function testAssociationIdentifierType(): void $this->assertSame(42, $result[0]); } - /** - * NEXT_MAJOR: Remove this dataprovider. - * - * [sortBy, sortOrder, isAddOrderBy]. - */ - public function getSortableInDataSourceIteratorDataProvider(): array - { - return [ - [null, null, false], - ['', 'ASC', false], - ['field', 'ASC', true], - ['field', null, true], - ]; - } - - /** - * NEXT_MAJOR: Remove this test. - * - * @group legacy - * - * @dataProvider getSortableInDataSourceIteratorDataProvider - * - * @param string|null $sortBy - * @param string|null $sortOrder - * @param bool $isAddOrderBy - */ - public function testSortableInDataSourceIterator($sortBy, $sortOrder, $isAddOrderBy): void - { - $datagrid = $this->getMockForAbstractClass(DatagridInterface::class); - $configuration = $this->getMockBuilder(Configuration::class)->getMock(); - $configuration->expects($this->any()) - ->method('getDefaultQueryHints') - ->willReturn([]); - - $em = $this->getMockBuilder(EntityManager::class) - ->disableOriginalConstructor() - ->getMock(); - - $em->expects($this->any()) - ->method('getConfiguration') - ->willReturn($configuration); - - $queryBuilder = $this->getMockBuilder(QueryBuilder::class) - ->setConstructorArgs([$em]) - ->getMock(); - $query = new Query($em); - - $proxyQuery = $this->getMockBuilder(ProxyQuery::class) - ->setConstructorArgs([$queryBuilder]) - ->setMethods(['getSortBy', 'getSortOrder', 'getRootAliases']) - ->getMock(); - - $proxyQuery->expects($this->any()) - ->method('getSortOrder') - ->willReturn($sortOrder); - - $proxyQuery->expects($this->any()) - ->method('getSortBy') - ->willReturn($sortBy); - - $queryBuilder->expects($isAddOrderBy ? $this->atLeastOnce() : $this->never()) - ->method('addOrderBy'); - - $proxyQuery->expects($this->any()) - ->method('getRootAliases') - ->willReturn(['a']); - - $queryBuilder->expects($this->any()) - ->method('getQuery') - ->willReturn($query); - - $datagrid->expects($this->any()) - ->method('getQuery') - ->willReturn($proxyQuery); - - $this->expectDeprecation('Method Sonata\DoctrineORMAdminBundle\Model\ModelManager::getDataSourceIterator() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.27 and will be removed in 4.0.'); - $this->modelManager->getDataSourceIterator($datagrid, []); - - if ($isAddOrderBy) { - $this->assertArrayHasKey($key = 'doctrine.customTreeWalkers', $hints = $query->getHints()); - $this->assertContains(OrderByToSelectWalker::class, $hints[$key]); - } - } - public function testModelReverseTransform(): void { $class = SimpleEntity::class; @@ -864,10 +776,7 @@ public function testAddIdentifiersToQuery(array $expectedParameters, array $iden ->method('andWhere') ->with($this->stringContains(sprintf('( p.%s = :field_', $identifierFieldNames[0]))); - $proxyQuery = $this->getMockBuilder(ProxyQuery::class) - ->setConstructorArgs([$queryBuilder]) - ->setMethods(['getSortBy']) - ->getMock(); + $proxyQuery = new ProxyQuery($queryBuilder); $metadata = $this->createMock(ClassMetadata::class); $metadata->expects($this->once())