Skip to content

Commit 48a62b8

Browse files
committed
Fix additional deprecations uncovered
1 parent 471f7e9 commit 48a62b8

File tree

6 files changed

+35
-28
lines changed

6 files changed

+35
-28
lines changed

src/Criteria.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ class Criteria
4040
*/
4141
public static function create(bool $accessRawFieldValues = false): self
4242
{
43-
$new = new static();
44-
$new->accessRawFieldValues = $accessRawFieldValues;
45-
46-
return $new;
43+
return new static(firstResult: 0, accessRawFieldValues: $accessRawFieldValues);
4744
}
4845

4946
/**

tests/ArrayCollectionTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public function testMultiColumnSortAppliesAllSorts(): void
477477
self::assertSame(
478478
$expected,
479479
$collection
480-
->matching(new Criteria(null, ['foo' => Order::Descending, 'bar' => Order::Descending], accessRawFieldValues: true))
480+
->matching(new Criteria(null, ['foo' => Order::Descending, 'bar' => Order::Descending], 0, null, accessRawFieldValues: true))
481481
->toArray(),
482482
);
483483
}

tests/ClosureExpressionVisitorTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\Common\Collections\ExpressionBuilder;
1313
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
1414
use PHPUnit\Framework\Attributes\Group;
15+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1516
use PHPUnit\Framework\Attributes\RequiresPhp;
1617
use PHPUnit\Framework\TestCase;
1718
use RuntimeException;
@@ -80,6 +81,7 @@ public function testGetObjectFieldValueNonexistentFieldAccessingRawValue(): void
8081
$this->visitor->getObjectFieldValue($object, 'fooBar', accessRawFieldValues: true);
8182
}
8283

84+
#[IgnoreDeprecations]
8385
public function testGetObjectFieldValueIsAccessor(): void
8486
{
8587
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -89,6 +91,7 @@ public function testGetObjectFieldValueIsAccessor(): void
8991
self::assertTrue($this->visitor->getObjectFieldValue($object, 'baz'));
9092
}
9193

94+
#[IgnoreDeprecations]
9295
public function testGetObjectFieldValueIsAccessorWithIsPrefix(): void
9396
{
9497
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -98,6 +101,7 @@ public function testGetObjectFieldValueIsAccessorWithIsPrefix(): void
98101
self::assertTrue($this->visitor->getObjectFieldValue($object, 'isBaz'));
99102
}
100103

104+
#[IgnoreDeprecations]
101105
public function testGetObjectFieldValueIsAccessorCamelCase(): void
102106
{
103107
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -109,6 +113,7 @@ public function testGetObjectFieldValueIsAccessorCamelCase(): void
109113
self::assertEquals(1, $this->visitor->getObjectFieldValue($object, 'fooBar'));
110114
}
111115

116+
#[IgnoreDeprecations]
112117
public function testGetObjectFieldValueIsAccessorBoth(): void
113118
{
114119
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -120,6 +125,7 @@ public function testGetObjectFieldValueIsAccessorBoth(): void
120125
self::assertEquals(2, $this->visitor->getObjectFieldValue($object, 'fooBar'));
121126
}
122127

128+
#[IgnoreDeprecations]
123129
public function testGetObjectFieldValueIsAccessorOnePublic(): void
124130
{
125131
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -131,6 +137,7 @@ public function testGetObjectFieldValueIsAccessorOnePublic(): void
131137
self::assertEquals(2, $this->visitor->getObjectFieldValue($object, 'fooBar'));
132138
}
133139

140+
#[IgnoreDeprecations]
134141
public function testGetObjectFieldValueIsAccessorBothPublic(): void
135142
{
136143
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -142,6 +149,7 @@ public function testGetObjectFieldValueIsAccessorBothPublic(): void
142149
self::assertEquals(2, $this->visitor->getObjectFieldValue($object, 'fooBar'));
143150
}
144151

152+
#[IgnoreDeprecations]
145153
public function testGetObjectFieldValueBlankAccessor(): void
146154
{
147155
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -152,6 +160,7 @@ public function testGetObjectFieldValueBlankAccessor(): void
152160
self::assertEquals(1, $this->visitor->getObjectFieldValue($object, 'fooBar'));
153161
}
154162

163+
#[IgnoreDeprecations]
155164
public function testGetObjectFieldValueMagicCallMethod(): void
156165
{
157166
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -161,6 +170,7 @@ public function testGetObjectFieldValueMagicCallMethod(): void
161170
self::assertEquals(3, $this->visitor->getObjectFieldValue($object, 'qux'));
162171
}
163172

173+
#[IgnoreDeprecations]
164174
public function testGetObjectFieldValueArrayAccess(): void
165175
{
166176
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -174,6 +184,7 @@ public function testGetObjectFieldValueArrayAccess(): void
174184
self::assertSame(33, $this->visitor->getObjectFieldValue($object, 'foo'));
175185
}
176186

187+
#[IgnoreDeprecations]
177188
public function testGetObjectFieldValuePublicPropertyIsNull(): void
178189
{
179190
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -429,7 +440,7 @@ public function testWalkUnknownCompositeExpressionThrowException(): void
429440
public function testSortByFieldAscending(): void
430441
{
431442
$objects = [new TestObject('b'), new TestObject('a'), new TestObject('c')];
432-
$sort = ClosureExpressionVisitor::sortByField('foo');
443+
$sort = ClosureExpressionVisitor::sortByField('foo', accessRawFieldValues: true);
433444

434445
usort($objects, $sort);
435446

@@ -441,7 +452,7 @@ public function testSortByFieldAscending(): void
441452
public function testSortByFieldDescending(): void
442453
{
443454
$objects = [new TestObject('b'), new TestObject('a'), new TestObject('c')];
444-
$sort = ClosureExpressionVisitor::sortByField('foo', -1);
455+
$sort = ClosureExpressionVisitor::sortByField('foo', -1, accessRawFieldValues: true);
445456

446457
usort($objects, $sort);
447458

@@ -456,7 +467,7 @@ public function testSortByFieldKeepOrderWhenSameValue(): void
456467
$secondElement = new TestObject('a');
457468

458469
$objects = [$firstElement, $secondElement];
459-
$sort = ClosureExpressionVisitor::sortByField('foo');
470+
$sort = ClosureExpressionVisitor::sortByField('foo', accessRawFieldValues: true);
460471

461472
usort($objects, $sort);
462473

@@ -466,8 +477,8 @@ public function testSortByFieldKeepOrderWhenSameValue(): void
466477
public function testSortDelegate(): void
467478
{
468479
$objects = [new TestObject('a', 'c'), new TestObject('a', 'b'), new TestObject('a', 'a')];
469-
$sort = ClosureExpressionVisitor::sortByField('bar', 1);
470-
$sort = ClosureExpressionVisitor::sortByField('foo', 1, $sort);
480+
$sort = ClosureExpressionVisitor::sortByField('bar', 1, accessRawFieldValues: true);
481+
$sort = ClosureExpressionVisitor::sortByField('foo', 1, $sort, accessRawFieldValues: true);
471482

472483
usort($objects, $sort);
473484

tests/CollectionTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\Common\Collections\Order;
1313
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
1414
use PHPUnit\Framework\Attributes\Group;
15+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1516
use RuntimeException;
1617
use stdClass;
1718

@@ -34,6 +35,7 @@ public function testToString(): void
3435
}
3536

3637
#[Group('DDC-1637')]
38+
#[IgnoreDeprecations]
3739
public function testMatchingLegacy(): void
3840
{
3941
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -57,7 +59,7 @@ public function testMatching(): void
5759
$this->collection[] = new TestObjectPrivatePropertyOnly(42);
5860
$this->collection[] = new TestObjectPrivatePropertyOnly(84);
5961

60-
$col = $this->collection->matching(new Criteria(Criteria::expr()->eq('fooBar', 42), accessRawFieldValues: true));
62+
$col = $this->collection->matching(new Criteria(Criteria::expr()->eq('fooBar', 42), firstResult: 0, accessRawFieldValues: true));
6163
self::assertInstanceOf(Collection::class, $col);
6264
self::assertNotSame($col, $this->collection);
6365
self::assertEquals(1, count($col));
@@ -71,6 +73,7 @@ public function testMatchingCallable(): void
7173
$col = $this->collection->matching(
7274
new Criteria(
7375
new Value(static fn (stdClass $test): bool => $test->foo === 1),
76+
firstResult: 0,
7477
accessRawFieldValues: true,
7578
),
7679
);
@@ -89,7 +92,7 @@ public function testMatchingUnknownThrowException(): void
8992
->setMockClassName('GenericExpression')
9093
->getMock();
9194

92-
$this->collection->matching(new Criteria($genericExpression));
95+
$this->collection->matching(new Criteria($genericExpression, firstResult: 0, accessRawFieldValues: true));
9396
}
9497

9598
#[Group('DDC-1637')]
@@ -109,6 +112,7 @@ public function testMatchingOrdering(): void
109112
}
110113

111114
#[Group('DDC-1637')]
115+
#[IgnoreDeprecations]
112116
public function testMatchingOrderingLegacy(): void
113117
{
114118
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');

tests/CriteriaTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class CriteriaTest extends TestCase
1717
{
1818
use VerifyDeprecations;
1919

20+
#[IgnoreDeprecations]
2021
public function testCreateLegacy(): void
2122
{
2223
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -58,13 +59,7 @@ public function testDeprecatedNullOffset(): void
5859
self::assertSame(20, $criteria->getMaxResults());
5960
}
6061

61-
public function testDefaultConstructorLegacy(): void
62-
{
63-
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
64-
65-
new Criteria();
66-
}
67-
62+
#[IgnoreDeprecations]
6863
public function testDefaultConstructor(): void
6964
{
7065
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/472');
@@ -81,7 +76,7 @@ public function testDefaultConstructor(): void
8176
public function testWhere(): void
8277
{
8378
$expr = new Comparison('field', '=', 'value');
84-
$criteria = new Criteria(accessRawFieldValues: true);
79+
$criteria = Criteria::create(accessRawFieldValues: true);
8580

8681
$criteria->where($expr);
8782

@@ -91,7 +86,7 @@ public function testWhere(): void
9186
public function testAndWhere(): void
9287
{
9388
$expr = new Comparison('field', '=', 'value');
94-
$criteria = new Criteria(accessRawFieldValues: true);
89+
$criteria = Criteria::create(accessRawFieldValues: true);
9590

9691
$criteria->where($expr);
9792
$expr = $criteria->getWhereExpression();
@@ -107,7 +102,7 @@ public function testAndWhere(): void
107102
public function testAndWhereWithoutWhere(): void
108103
{
109104
$expr = new Comparison('field', '=', 'value');
110-
$criteria = new Criteria(accessRawFieldValues: true);
105+
$criteria = Criteria::create(accessRawFieldValues: true);
111106

112107
$criteria->andWhere($expr);
113108

@@ -117,7 +112,7 @@ public function testAndWhereWithoutWhere(): void
117112
public function testOrWhere(): void
118113
{
119114
$expr = new Comparison('field', '=', 'value');
120-
$criteria = new Criteria(accessRawFieldValues: true);
115+
$criteria = Criteria::create(accessRawFieldValues: true);
121116

122117
$criteria->where($expr);
123118
$expr = $criteria->getWhereExpression();
@@ -133,7 +128,7 @@ public function testOrWhere(): void
133128
public function testOrWhereWithoutWhere(): void
134129
{
135130
$expr = new Comparison('field', '=', 'value');
136-
$criteria = new Criteria(accessRawFieldValues: true);
131+
$criteria = Criteria::create(accessRawFieldValues: true);
137132

138133
$criteria->orWhere($expr);
139134

@@ -164,14 +159,14 @@ public function testPassingNonOrderEnumToOrderByIsDeprecated(): void
164159
public function testConstructingCriteriaWithNonOrderEnumIsDeprecated(): void
165160
{
166161
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/389');
167-
$criteria = new Criteria(null, ['foo' => 'ASC'], accessRawFieldValues: true);
162+
$criteria = new Criteria(null, ['foo' => 'ASC'], firstResult: 0, accessRawFieldValues: true);
168163
}
169164

170165
public function testUsingOrderEnumIsTheRightWay(): void
171166
{
172167
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/collections/pull/389');
173-
Criteria::create()->orderBy(['foo' => Order::Ascending]);
174-
new Criteria(null, ['foo' => Order::Ascending], accessRawFieldValues: true);
168+
Criteria::create(accessRawFieldValues: true)->orderBy(['foo' => Order::Ascending]);
169+
new Criteria(null, ['foo' => Order::Ascending], firstResult: 0, accessRawFieldValues: true);
175170
}
176171

177172
#[IgnoreDeprecations]

tests/DerivedCollectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public function testDerivedClassCreation(): void
2222
self::assertInstanceOf(DerivedArrayCollection::class, $collection->map($closure));
2323
self::assertInstanceOf(DerivedArrayCollection::class, $collection->filter($closure));
2424
self::assertContainsOnlyInstancesOf(DerivedArrayCollection::class, $collection->partition($closure));
25-
self::assertInstanceOf(DerivedArrayCollection::class, $collection->matching(new Criteria()));
25+
self::assertInstanceOf(DerivedArrayCollection::class, $collection->matching(Criteria::create(accessRawFieldValues: true)));
2626
}
2727
}

0 commit comments

Comments
 (0)