Skip to content

Commit c472a15

Browse files
authored
Stop using deprecated Collections constants (#12214)
1 parent 28dd327 commit c472a15

File tree

5 files changed

+11
-24
lines changed

5 files changed

+11
-24
lines changed

src/Mapping/Driver/XmlDriver.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Doctrine\ORM\Mapping\Driver;
66

7-
use Doctrine\Common\Collections\Criteria;
8-
use Doctrine\Common\Collections\Order;
97
use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder;
108
use Doctrine\ORM\Mapping\ClassMetadata;
119
use Doctrine\ORM\Mapping\MappingException;
@@ -21,7 +19,6 @@
2119
use function constant;
2220
use function count;
2321
use function defined;
24-
use function enum_exists;
2522
use function explode;
2623
use function extension_loaded;
2724
use function file_get_contents;
@@ -409,10 +406,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
409406
if (isset($oneToManyElement->{'order-by'})) {
410407
$orderBy = [];
411408
foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} ?? [] as $orderByField) {
412-
$orderBy[(string) $orderByField['name']] = isset($orderByField['direction'])
413-
? (string) $orderByField['direction']
414-
// @phpstan-ignore classConstant.deprecated
415-
: (enum_exists(Order::class) ? Order::Ascending->value : Criteria::ASC);
409+
$orderBy[(string) $orderByField['name']] = (string) ($orderByField['direction'] ?? 'ASC');
416410
}
417411

418412
$mapping['orderBy'] = $orderBy;
@@ -538,10 +532,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
538532
if (isset($manyToManyElement->{'order-by'})) {
539533
$orderBy = [];
540534
foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} ?? [] as $orderByField) {
541-
$orderBy[(string) $orderByField['name']] = isset($orderByField['direction'])
542-
? (string) $orderByField['direction']
543-
// @phpstan-ignore classConstant.deprecated
544-
: (enum_exists(Order::class) ? Order::Ascending->value : Criteria::ASC);
535+
$orderBy[(string) $orderByField['name']] = (string) ($orderByField['direction'] ?? 'ASC');
545536
}
546537

547538
$mapping['orderBy'] = $orderBy;

tests/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use PHPUnit\Framework\Attributes\Group;
1818

1919
use function assert;
20-
use function class_exists;
2120
use function get_class;
2221

2322
/**
@@ -438,7 +437,7 @@ public function testManyToManyOrderByIsNotIgnored(): void
438437
$user = $this->_em->find($user::class, $user->id);
439438

440439
$criteria = Criteria::create()
441-
->orderBy(['name' => class_exists(Order::class) ? Order::Ascending : Criteria::ASC]);
440+
->orderBy(['name' => Order::Ascending]);
442441

443442
self::assertEquals(
444443
['A', 'B', 'C', 'Developers_0'],
@@ -478,7 +477,7 @@ public function testManyToManyOrderByHonorsFieldNameColumnNameAliases(): void
478477
$user = $this->_em->find($user::class, $user->id);
479478

480479
$criteria = Criteria::create()
481-
->orderBy(['name' => class_exists(Order::class) ? Order::Ascending : Criteria::ASC]);
480+
->orderBy(['name' => Order::Ascending]);
482481

483482
self::assertEquals(
484483
['A', 'B', 'C'],

tests/Tests/ORM/Functional/Ticket/GH7820Test.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Doctrine\Tests\ORM\Functional\Ticket;
66

7-
use Doctrine\Common\Collections\Criteria;
87
use Doctrine\DBAL\Platforms\AbstractPlatform;
98
use Doctrine\DBAL\Types\StringType;
109
use Doctrine\DBAL\Types\Type;
@@ -146,7 +145,7 @@ private function fetchSongLinesWithPaginator(): array
146145
{
147146
$query = $this->_em->getRepository(GH7820Line::class)
148147
->createQueryBuilder('l')
149-
->orderBy('l.lineNumber', Criteria::ASC)
148+
->orderBy('l.lineNumber', 'ASC')
150149
->setMaxResults(100);
151150

152151
return array_map(static fn (GH7820Line $line): string => $line->toString(), iterator_to_array(new Paginator($query)));

tests/Tests/ORM/Mapping/XmlMappingDriverTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Doctrine\Tests\ORM\Mapping;
66

7-
use Doctrine\Common\Collections\Criteria;
87
use Doctrine\ORM\Cache\Exception\CacheException;
98
use Doctrine\ORM\Mapping\ClassMetadata;
109
use Doctrine\ORM\Mapping\ClassMetadataFactory;
@@ -255,8 +254,8 @@ public function testOneToManyDefaultOrderByAsc(): void
255254
$class->initializeReflection(new RuntimeReflectionService());
256255
$driver->loadMetadataForClass(GH7141Article::class, $class);
257256

258-
self::assertEquals(
259-
Criteria::ASC,
257+
self::assertSame(
258+
'ASC',
260259
$class->getMetadataValue('associationMappings')['tags']->orderBy['position'],
261260
);
262261
}
@@ -269,8 +268,8 @@ public function testManyToManyDefaultOrderByAsc(): void
269268
$driver = $this->loadDriver();
270269
$driver->loadMetadataForClass(GH7316Article::class, $class);
271270

272-
self::assertEquals(
273-
Criteria::ASC,
271+
self::assertSame(
272+
'ASC',
274273
$class->getMetadataValue('associationMappings')['tags']->orderBy['position'],
275274
);
276275
}

tests/Tests/ORM/QueryBuilderTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use RuntimeException;
3131

3232
use function array_filter;
33-
use function class_exists;
3433

3534
/**
3635
* Test case for the QueryBuilder class used to build DQL query string in a
@@ -615,7 +614,7 @@ public function testAddCriteriaOrder(): void
615614
->from(CmsUser::class, 'u');
616615

617616
$criteria = new Criteria();
618-
$criteria->orderBy(['field' => class_exists(Order::class) ? Order::Descending : Criteria::DESC]);
617+
$criteria->orderBy(['field' => Order::Descending]);
619618

620619
$qb->addCriteria($criteria);
621620

@@ -632,7 +631,7 @@ public function testAddCriteriaOrderOnJoinAlias(): void
632631
->join('u.article', 'a');
633632

634633
$criteria = new Criteria();
635-
$criteria->orderBy(['a.field' => class_exists(Order::class) ? Order::Descending : Criteria::DESC]);
634+
$criteria->orderBy(['a.field' => Order::Descending]);
636635

637636
$qb->addCriteria($criteria);
638637

0 commit comments

Comments
 (0)