Skip to content

Commit 310f9bc

Browse files
authored
[3.x] Use PHPUnit 12 (#2961)
1 parent 1d2ec66 commit 310f9bc

File tree

10 files changed

+37
-50
lines changed

10 files changed

+37
-50
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"phpstan/phpstan": "^2.1",
4848
"phpstan/phpstan-deprecation-rules": "^2.0",
4949
"phpstan/phpstan-phpunit": "^2.0",
50-
"phpunit/phpunit": "^10.5.58|^11.5.43",
50+
"phpunit/phpunit": "^12.5.1",
5151
"squizlabs/php_codesniffer": "^4",
5252
"symfony/cache": "^5.4 || ^6.0 || ^7.0 || ^8.0",
5353
"symfony/uid": "^5.4 || ^6.0 || ^7.0 || ^8.0",

tests/Tests/Aggregation/AggregationTestTrait.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ protected function getTestAggregationBuilder(string $documentName = User::class)
1717
return new Builder($this->dm, $documentName);
1818
}
1919

20-
/** @return MockObject|AggregationExpr */
21-
protected function getMockAggregationExpr()
20+
protected function getMockAggregationExpr(): AggregationExpr&MockObject
2221
{
2322
return $this->createMock(AggregationExpr::class);
2423
}
2524

26-
/** @return MockObject|QueryExpr */
27-
protected function getMockQueryExpr()
25+
protected function getMockQueryExpr(): QueryExpr&MockObject
2826
{
2927
return $this->createMock(QueryExpr::class);
3028
}

tests/Tests/Events/OnClassMetadataNotFoundEventArgsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class OnClassMetadataNotFoundEventArgsTest extends TestCase
1414
{
1515
public function testEventArgsMutability(): void
1616
{
17-
$documentManager = $this->createMock(DocumentManager::class);
17+
$documentManager = $this->createStub(DocumentManager::class);
1818

1919
$args = new OnClassMetadataNotFoundEventArgs(stdClass::class, $documentManager);
2020

tests/Tests/Functional/DocumentPersisterTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ public function testExecuteInsertsRespectsWriteConcern(string $class, string|int
635635
$collection = $this->createMock(Collection::class);
636636
$collection->expects($this->once())
637637
->method('insertMany')
638-
->with($this->isType('array'), $this->logicalAnd($this->arrayHasKey('writeConcern'), $this->containsEqual(new WriteConcern($writeConcern))));
638+
->with($this->isArray(), $this->logicalAnd($this->arrayHasKey('writeConcern'), $this->containsEqual(new WriteConcern($writeConcern))));
639639

640640
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
641641
$reflectionProperty->setValue($documentPersister, $collection);
@@ -656,7 +656,7 @@ public function testExecuteInsertsOmitsWriteConcernInTransaction(string $class,
656656
$collection = $this->createMock(Collection::class);
657657
$collection->expects($this->once())
658658
->method('insertMany')
659-
->with($this->isType('array'), $this->logicalNot($this->arrayHasKey('writeConcern')));
659+
->with($this->isArray(), $this->logicalNot($this->arrayHasKey('writeConcern')));
660660

661661
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
662662
$reflectionProperty->setValue($documentPersister, $collection);
@@ -677,7 +677,7 @@ public function testExecuteUpsertsRespectsWriteConcern(string $class, string|int
677677
$collection = $this->createMock(Collection::class);
678678
$collection->expects($this->once())
679679
->method('updateOne')
680-
->with($this->isType('array'), $this->isType('array'), $this->logicalAnd($this->arrayHasKey('writeConcern'), $this->containsEqual(new WriteConcern($writeConcern))));
680+
->with($this->isArray(), $this->isArray(), $this->logicalAnd($this->arrayHasKey('writeConcern'), $this->containsEqual(new WriteConcern($writeConcern))));
681681

682682
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
683683
$reflectionProperty->setValue($documentPersister, $collection);
@@ -699,7 +699,7 @@ public function testExecuteUpsertsDoesNotUseWriteConcernInTransaction(string $cl
699699
$collection = $this->createMock(Collection::class);
700700
$collection->expects($this->once())
701701
->method('updateOne')
702-
->with($this->isType('array'), $this->logicalNot($this->arrayHasKey('writeConcern')));
702+
->with($this->isArray(), $this->logicalNot($this->arrayHasKey('writeConcern')));
703703

704704
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
705705
$reflectionProperty->setValue($documentPersister, $collection);
@@ -721,7 +721,7 @@ public function testRemoveRespectsWriteConcern(string $class, string|int $writeC
721721
$collection = $this->createMock(Collection::class);
722722
$collection->expects($this->once())
723723
->method('deleteOne')
724-
->with($this->isType('array'), $this->logicalAnd($this->arrayHasKey('writeConcern'), $this->containsEqual(new WriteConcern($writeConcern))));
724+
->with($this->isArray(), $this->logicalAnd($this->arrayHasKey('writeConcern'), $this->containsEqual(new WriteConcern($writeConcern))));
725725

726726
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
727727
$reflectionProperty->setValue($documentPersister, $collection);
@@ -745,7 +745,7 @@ public function testRemoveDoesNotUseWriteConcernInTransaction(string $class, str
745745
$collection = $this->createMock(Collection::class);
746746
$collection->expects($this->once())
747747
->method('deleteOne')
748-
->with($this->isType('array'), $this->logicalNot($this->arrayHasKey('writeConcern')));
748+
->with($this->isArray(), $this->logicalNot($this->arrayHasKey('writeConcern')));
749749

750750
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
751751
$reflectionProperty->setValue($documentPersister, $collection);
@@ -768,7 +768,7 @@ public function testDefaultWriteConcernIsRespected(): void
768768
$collection = $this->createMock(Collection::class);
769769
$collection->expects($this->once())
770770
->method('insertMany')
771-
->with($this->isType('array'), $this->equalTo(['writeConcern' => new WriteConcern(0)]));
771+
->with($this->isArray(), $this->equalTo(['writeConcern' => new WriteConcern(0)]));
772772

773773
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
774774
$reflectionProperty->setValue($documentPersister, $collection);
@@ -790,7 +790,7 @@ public function testDefaultWriteConcernIsIgnoredInTransaction(): void
790790
$collection = $this->createMock(Collection::class);
791791
$collection->expects($this->once())
792792
->method('insertMany')
793-
->with($this->isType('array'), $this->logicalNot($this->arrayHasKey('writeConcern')));
793+
->with($this->isArray(), $this->logicalNot($this->arrayHasKey('writeConcern')));
794794

795795
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
796796
$reflectionProperty->setValue($documentPersister, $collection);
@@ -812,7 +812,7 @@ public function testDefaultWriteConcernIsRespectedBackwardCompatibility(): void
812812
$collection = $this->createMock(Collection::class);
813813
$collection->expects($this->once())
814814
->method('insertMany')
815-
->with($this->isType('array'), $this->equalTo(['writeConcern' => new WriteConcern(0)]));
815+
->with($this->isArray(), $this->equalTo(['writeConcern' => new WriteConcern(0)]));
816816

817817
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
818818
$reflectionProperty->setValue($documentPersister, $collection);

tests/Tests/Functional/SplObjectHashCollisionsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class SplObjectHashCollisionsTest extends BaseTestCase
1515
{
1616
/** @param callable(DocumentManager, object=): void $f */
1717
#[DataProvider('provideParentAssociationsIsCleared')]
18-
public function testParentAssociationsIsCleared(callable $f): void
18+
public function testParentAssociationsIsCleared(callable $f, int $leftover): void
1919
{
2020
$d = new SplColDoc();
2121
$d->one = new SplColEmbed('d.one.v1');

tests/Tests/Proxy/Factory/ProxyFactoryTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
class ProxyFactoryTest extends BaseTestCase
2121
{
22-
/** @var Client|MockObject */
23-
private Client $client;
22+
private Client&MockObject $client;
2423

2524
public function testProxyInitializeWithException(): void
2625
{

tests/Tests/Query/BuilderTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ public static function provideProxiedExprMethods(): array
497497
'type()' => ['type', [7]],
498498
'all()' => ['all', [['value1', 'value2']]],
499499
'mod()' => ['mod', [2, 0]],
500-
'near()' => ['near', [1, 2], null, 5, 10],
501-
'nearSphere()' => ['nearSphere', [1, 2], null, 5, 10],
500+
'near()' => ['near', [[1, 2], null, 5, 10]],
501+
'nearSphere()' => ['nearSphere', [[1, 2], null, 5, 10]],
502502
'geoIntersects()' => ['geoIntersects', [self::createGeometry()]],
503503
'geoWithin()' => ['geoWithin', [self::createGeometry()]],
504504
'geoWithinBox()' => ['geoWithinBox', [1, 2, 3, 4]],
@@ -864,8 +864,7 @@ private function getTestQueryBuilder(): Builder
864864
return new Builder($this->dm, User::class);
865865
}
866866

867-
/** @return MockObject&Expr */
868-
private function getMockExpr()
867+
private function getMockExpr(): Expr&MockObject
869868
{
870869
return $this->createMock(Expr::class);
871870
}

tests/Tests/QueryTest.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@
2222
use MongoDB\BSON\Int64;
2323
use MongoDB\BSON\ObjectId;
2424
use MongoDB\Collection;
25-
use MongoDB\Driver\CursorId;
2625
use MongoDB\Driver\CursorInterface;
2726
use MongoDB\Driver\ReadPreference;
2827
use MongoDB\Driver\Server;
2928
use PHPUnit\Framework\Attributes\DataProvider;
3029
use PHPUnit\Framework\MockObject\MockObject;
30+
use PHPUnit\Framework\MockObject\Stub;
3131
use Traversable;
3232

3333
use function array_keys;
34-
use function class_exists;
3534
use function iterator_to_array;
3635

3736
use const DOCTRINE_MONGODB_DATABASE;
@@ -426,7 +425,7 @@ public function testConstructorShouldThrowExceptionForInvalidType(): void
426425
{
427426
$this->expectException(InvalidArgumentException::class);
428427

429-
new Query($this->dm, new ClassMetadata(User::class), $this->getMockCollection(), ['type' => -1], []);
428+
new Query($this->dm, new ClassMetadata(User::class), $this->createStub(Collection::class), ['type' => -1], []);
430429
}
431430

432431
/** @param Query::TYPE_* $type */
@@ -502,7 +501,7 @@ public function testCountOptionInheritance(): void
502501

503502
public function testFindWithHint(): void
504503
{
505-
$cursor = $this->createCursorMock();
504+
$cursor = $this->createCursorStub();
506505

507506
$collection = $this->getMockCollection();
508507
$collection->expects($this->once())
@@ -529,7 +528,7 @@ public function testFindOptionInheritance(): void
529528
$nearest = new ReadPreference('nearest');
530529
$secondaryPreferred = new ReadPreference('secondaryPreferred');
531530

532-
$cursor = $this->createCursorMock();
531+
$cursor = $this->createCursorStub();
533532

534533
$collection = $this->getMockCollection();
535534
$collection->expects($this->once())
@@ -620,20 +619,14 @@ public function key(): int
620619
iterator_to_array($iterator);
621620
}
622621

623-
/** @return MockObject&Collection */
624-
private function getMockCollection()
622+
private function getMockCollection(): Collection&MockObject
625623
{
626624
return $this->createMock(Collection::class);
627625
}
628626

629-
private function createCursorMock(): CursorInterface|Traversable
627+
private function createCursorStub(): CursorInterface&Stub
630628
{
631-
return $this->createMock(
632-
// Use the cursorID class to differentiate between 1.x and 2.x
633-
class_exists(CursorId::class)
634-
? Traversable::class
635-
: CursorInterface::class,
636-
);
629+
return $this->createStub(CursorInterface::class);
637630
}
638631
}
639632

tests/Tests/SchemaManagerTest.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
use PHPUnit\Framework\Constraint\Constraint;
4646
use PHPUnit\Framework\Constraint\IsEqual;
4747
use PHPUnit\Framework\MockObject\MockObject;
48+
use PHPUnit\Framework\MockObject\Stub;
4849
use ReflectionProperty;
4950

5051
use function array_count_values;
@@ -88,7 +89,7 @@ class SchemaManagerTest extends BaseTestCase
8889
/** @var array<Collection&MockObject> */
8990
private array $documentCollections = [];
9091

91-
/** @var array<Bucket&MockObject> */
92+
/** @var array<Bucket&Stub> */
9293
private array $documentBuckets = [];
9394

9495
/** @var array<Database&MockObject> */
@@ -100,16 +101,16 @@ public function setUp(): void
100101
{
101102
parent::setUp();
102103

103-
$client = $this->createMock(Client::class);
104-
$this->dm = DocumentManager::create($client, $this->dm->getConfiguration(), $this->createMock(EventManager::class));
104+
$client = $this->createStub(Client::class);
105+
$this->dm = DocumentManager::create($client, $this->dm->getConfiguration(), $this->createStub(EventManager::class));
105106

106107
foreach ($this->dm->getMetadataFactory()->getAllMetadata() as $cm) {
107108
if ($cm->isMappedSuperclass || $cm->isEmbeddedDocument || $cm->isQueryResultDocument) {
108109
continue;
109110
}
110111

111112
if ($cm->isFile) {
112-
$this->documentBuckets[$cm->getBucketName()] = $this->getMockBucket();
113+
$this->documentBuckets[$cm->getBucketName()] = $this->getBucketStub();
113114
} else {
114115
$this->documentCollections[$cm->getCollection()] = $this->getMockCollection($cm->getCollection());
115116
}
@@ -1407,30 +1408,27 @@ private function getDatabaseName(ClassMetadata $cm): string
14071408
return ($cm->getDatabase() ?: $this->dm->getConfiguration()->getDefaultDB()) ?: 'doctrine';
14081409
}
14091410

1410-
/** @return Bucket&MockObject */
1411-
private function getMockBucket()
1411+
private function getBucketStub(): Bucket&Stub
14121412
{
1413-
$mock = $this->createMock(Bucket::class);
1413+
$mock = $this->createStub(Bucket::class);
14141414
$mock->method('getFilesCollection')->willReturn($this->getMockCollection());
14151415
$mock->method('getChunksCollection')->willReturn($this->getMockCollection());
14161416

14171417
return $mock;
14181418
}
14191419

1420-
/** @return Collection&MockObject */
1421-
private function getMockCollection(?string $name = null)
1420+
private function getMockCollection(?string $name = null): Collection&MockObject
14221421
{
14231422
$collection = $this->createMock(Collection::class);
1424-
$collection->method('getCollectionName')->willReturnCallback(static fn () => $name);
1423+
$collection->expects($this->atLeast(0))->method('getCollectionName')->willReturnCallback(static fn () => $name);
14251424

14261425
return $collection;
14271426
}
14281427

1429-
/** @return Database&MockObject */
1430-
private function getMockDatabase()
1428+
private function getMockDatabase(): Database&MockObject
14311429
{
14321430
$db = $this->createMock(Database::class);
1433-
$db->method('getCollection')->willReturnCallback(fn (string $collection) => $this->documentCollections[$collection]);
1431+
$db->expects($this->atLeast(0))->method('getCollection')->willReturnCallback(fn (string $collection) => $this->documentCollections[$collection]);
14341432
$db->method('selectGridFSBucket')->willReturnCallback(fn (array $options) => $this->documentBuckets[$options['bucketName']]);
14351433
$db->method('listCollections')->willReturnCallback(function () {
14361434
$collections = [];

tests/Tests/UnitOfWorkTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ public function testTransactionalCommitOmitsWriteConcernInOperation(): void
559559
$collection = $this->createMock(MongoDBCollection::class);
560560
$collection->expects($this->once())
561561
->method('insertMany')
562-
->with($this->isType('array'), $this->logicalNot($this->arrayHasKey('writeConcern')));
562+
->with($this->isArray(), $this->logicalNot($this->arrayHasKey('writeConcern')));
563563

564564
$documentPersister = $this->uow->getDocumentPersister(ForumUser::class);
565565

0 commit comments

Comments
 (0)