From dbbca95f0b323ad81431d2977130bff8c48604ab Mon Sep 17 00:00:00 2001 From: HypeMC <2445045+HypeMC@users.noreply.github.com> Date: Sat, 21 Feb 2026 20:50:02 +0100 Subject: [PATCH 1/2] Fix CS (#134) --- .../Cache/PropertyResolver/MethodResolverTest.php | 2 +- .../Subscription/PurgeSubscriptionProviderTest.php | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Cache/PropertyResolver/MethodResolverTest.php b/tests/Cache/PropertyResolver/MethodResolverTest.php index df793f1f..124f6b3b 100644 --- a/tests/Cache/PropertyResolver/MethodResolverTest.php +++ b/tests/Cache/PropertyResolver/MethodResolverTest.php @@ -46,7 +46,7 @@ public function testResolveMethod(string $target, int $invocationCount): void $classMetadata = self::createStub(ClassMetadata::class); $classMetadata->method('hasField') - ->willReturnCallback(fn (string $property) => match ($property) { + ->willReturnCallback(static fn (string $property) => match ($property) { 'bar' => true, 'baz' => true, }); diff --git a/tests/Cache/Subscription/PurgeSubscriptionProviderTest.php b/tests/Cache/Subscription/PurgeSubscriptionProviderTest.php index 542ba304..ec97af5e 100644 --- a/tests/Cache/Subscription/PurgeSubscriptionProviderTest.php +++ b/tests/Cache/Subscription/PurgeSubscriptionProviderTest.php @@ -38,7 +38,7 @@ public function testWithoutTarget(RouteMetadata $routeMetadata, array $expectedS { $routeMetadataProvider = self::createStub(RouteMetadataProviderInterface::class); $routeMetadataProvider->method('provide') - ->willReturnCallback(function () use ($routeMetadata) { + ->willReturnCallback(static function () use ($routeMetadata) { yield $routeMetadata; }); @@ -138,7 +138,7 @@ public function testWithTarget(RouteMetadata $routeMetadata, array $targetResolv { $subscriptionResolver = self::createStub(SubscriptionResolverInterface::class); $subscriptionResolver->method('resolveSubscription') - ->willReturnCallback(function () use ($expectedSubscriptions) { + ->willReturnCallback(static function () use ($expectedSubscriptions) { static $i = 0; yield $expectedSubscriptions[$i++]; @@ -148,7 +148,7 @@ public function testWithTarget(RouteMetadata $routeMetadata, array $targetResolv $routeMetadataProvider = self::createStub(RouteMetadataProviderInterface::class); $routeMetadataProvider->method('provide') - ->willReturnCallback(function () use ($routeMetadata) { + ->willReturnCallback(static function () use ($routeMetadata) { yield $routeMetadata; }); @@ -300,7 +300,7 @@ public function testExceptionIsThrownWhenEntityMetadataIsNotFound(): void { $routeMetadataProvider = self::createStub(RouteMetadataProviderInterface::class); $routeMetadataProvider->method('provide') - ->willReturnCallback(function () { + ->willReturnCallback(static function () { yield new RouteMetadata( routeName: 'foo', route: new Route('/foo'), @@ -338,7 +338,7 @@ public function testWithMissingRouteParams( ): void { $routeMetadataProvider = self::createStub(RouteMetadataProviderInterface::class); $routeMetadataProvider->method('provide') - ->willReturnCallback(function () use ($routeMetadata) { + ->willReturnCallback(static function () use ($routeMetadata) { yield $routeMetadata; }); @@ -506,7 +506,7 @@ public function testExceptionIsThrownOnInvalidIfExpression(string $if, string $e { $routeMetadataProvider = self::createStub(RouteMetadataProviderInterface::class); $routeMetadataProvider->method('provide') - ->willReturnCallback(function () use ($if): iterable { + ->willReturnCallback(static function () use ($if): iterable { yield new RouteMetadata( routeName: 'foo', route: new Route('/{foo}'), @@ -529,7 +529,7 @@ class: 'FooEntity', public function getFunctions(): array { return [ - new ExpressionFunction('valid_function', function () {}, function () {}), + new ExpressionFunction('valid_function', static function () {}, static function () {}), ]; } }, From 397ad7ae02687d0f1b8051a117a2bfbc1ec07483 Mon Sep 17 00:00:00 2001 From: HypeMC <2445045+HypeMC@users.noreply.github.com> Date: Sat, 21 Feb 2026 21:31:12 +0100 Subject: [PATCH 2/2] Don't call `with()` on stubs (#135) --- .../AssociationResolverTestCase.php | 10 ++++--- .../EmbeddableResolverDoctrine3Test.php | 5 ++-- .../PropertyResolver/PropertyResolverTest.php | 24 +++++++++------ .../PurgeSubscriptionProviderTest.php | 15 ++++++---- .../TargetResolver/ForGroupsResolverTest.php | 5 ++-- .../RemovedEntityRouteProviderTest.php | 30 +++++++++---------- 6 files changed, 51 insertions(+), 38 deletions(-) diff --git a/tests/Cache/PropertyResolver/AssociationResolverTestCase.php b/tests/Cache/PropertyResolver/AssociationResolverTestCase.php index 7eb93ec0..8abe3fc1 100644 --- a/tests/Cache/PropertyResolver/AssociationResolverTestCase.php +++ b/tests/Cache/PropertyResolver/AssociationResolverTestCase.php @@ -30,8 +30,9 @@ public function testResolveAssociations( bool $isGetAssociationMappedByTargetFieldCalled, bool $isAssociationInverseSide, ): void { - $extractor = self::createStub(PropertyReadInfoExtractorInterface::class); - $extractor->method('getReadInfo') + $extractor = $this->createMock(PropertyReadInfoExtractorInterface::class); + $extractor->expects(self::once()) + ->method('getReadInfo') ->with('BarEntity', 'barProperty') ->willReturn( new PropertyReadInfo( @@ -115,8 +116,9 @@ public function testFieldNotAssociation(): void self::createStub(PropertyReadInfoExtractorInterface::class), ); - $classMetadata = self::createStub(ClassMetadata::class); - $classMetadata->method('hasAssociation') + $classMetadata = $this->createMock(ClassMetadata::class); + $classMetadata->expects(self::once()) + ->method('hasAssociation') ->with('fooProperty') ->willReturn(false); diff --git a/tests/Cache/PropertyResolver/EmbeddableResolverDoctrine3Test.php b/tests/Cache/PropertyResolver/EmbeddableResolverDoctrine3Test.php index b0292000..df1f799c 100644 --- a/tests/Cache/PropertyResolver/EmbeddableResolverDoctrine3Test.php +++ b/tests/Cache/PropertyResolver/EmbeddableResolverDoctrine3Test.php @@ -48,8 +48,9 @@ public function testResolveEmbeddable(): void ->with('BarEntity') ->willReturn($embeddableClassMetadata); - $managerRegistry = self::createStub(ManagerRegistry::class); - $managerRegistry->method('getManagerForClass') + $managerRegistry = $this->createMock(ManagerRegistry::class); + $managerRegistry->expects(self::once()) + ->method('getManagerForClass') ->with('ParentClass') ->willReturn($entityManager); diff --git a/tests/Cache/PropertyResolver/PropertyResolverTest.php b/tests/Cache/PropertyResolver/PropertyResolverTest.php index 4586dad8..a81999c0 100644 --- a/tests/Cache/PropertyResolver/PropertyResolverTest.php +++ b/tests/Cache/PropertyResolver/PropertyResolverTest.php @@ -28,9 +28,10 @@ public function testResolveField(): void managerRegistry: self::createStub(ManagerRegistry::class), ); - $classMetadata = self::createStub(ClassMetadata::class); + $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->subClasses = []; - $classMetadata->method('hasField') + $classMetadata->expects(self::once()) + ->method('hasField') ->with('fooProperty') ->willReturn(true); @@ -67,9 +68,10 @@ public function testTargetNotField(): void managerRegistry: self::createStub(ManagerRegistry::class), ); - $classMetadata = self::createStub(ClassMetadata::class); + $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->subClasses = []; - $classMetadata->method('hasField') + $classMetadata->expects(self::once()) + ->method('hasField') ->with('fooProperty') ->willReturn(false); @@ -101,18 +103,22 @@ public function testResolveAssociation(): void managerRegistry: self::createStub(ManagerRegistry::class), ); - $classMetadata = self::createStub(ClassMetadata::class); + $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->subClasses = []; - $classMetadata->method('hasField') + $classMetadata->expects(self::once()) + ->method('hasField') ->with('fooProperty') ->willReturn(false); - $classMetadata->method('hasAssociation') + $classMetadata->expects(self::once()) + ->method('hasAssociation') ->with('fooProperty') ->willReturn(true); - $classMetadata->method('isSingleValuedAssociation') + $classMetadata->expects(self::once()) + ->method('isSingleValuedAssociation') ->with('fooProperty') ->willReturn(true); - $classMetadata->method('isAssociationInverseSide') + $classMetadata->expects(self::once()) + ->method('isAssociationInverseSide') ->with('fooProperty') ->willReturn(false); diff --git a/tests/Cache/Subscription/PurgeSubscriptionProviderTest.php b/tests/Cache/Subscription/PurgeSubscriptionProviderTest.php index ec97af5e..91201f70 100644 --- a/tests/Cache/Subscription/PurgeSubscriptionProviderTest.php +++ b/tests/Cache/Subscription/PurgeSubscriptionProviderTest.php @@ -154,8 +154,9 @@ public function testWithTarget(RouteMetadata $routeMetadata, array $targetResolv $classMetadata = self::createStub(ClassMetadata::class); - $entityManager = self::createStub(EntityManagerInterface::class); - $entityManager->method('getClassMetadata') + $entityManager = $this->createMock(EntityManagerInterface::class); + $entityManager->expects(self::once()) + ->method('getClassMetadata') ->with('FooEntity') ->willReturn($classMetadata); @@ -165,13 +166,15 @@ public function testWithTarget(RouteMetadata $routeMetadata, array $targetResolv ->with('FooEntity') ->willReturn($entityManager); - $dummyTargetResolver = self::createStub(TargetResolverInterface::class); - $dummyTargetResolver->method('resolve') + $dummyTargetResolver = $this->createMock(TargetResolverInterface::class); + $dummyTargetResolver->expects(self::once()) + ->method('resolve') ->with($routeMetadata->purgeOn->target, $routeMetadata) ->willReturn($targetResolverReturn); - $targetResolverLocator = self::createStub(ContainerInterface::class); - $targetResolverLocator->method('get') + $targetResolverLocator = $this->createMock(ContainerInterface::class); + $targetResolverLocator->expects(self::once()) + ->method('get') ->with(DummyTarget::class) ->willReturn($dummyTargetResolver); diff --git a/tests/Cache/TargetResolver/ForGroupsResolverTest.php b/tests/Cache/TargetResolver/ForGroupsResolverTest.php index 942cef48..c4c5c8db 100644 --- a/tests/Cache/TargetResolver/ForGroupsResolverTest.php +++ b/tests/Cache/TargetResolver/ForGroupsResolverTest.php @@ -20,8 +20,9 @@ final class ForGroupsResolverTest extends TestCase { public function testResolve(): void { - $propertyListExtractor = self::createStub(PropertyListExtractorInterface::class); - $propertyListExtractor->method('getProperties') + $propertyListExtractor = $this->createMock(PropertyListExtractorInterface::class); + $propertyListExtractor->expects(self::once()) + ->method('getProperties') ->with('FooEntity', ['serializer_groups' => ['group1']]) ->willReturn(['property1', 'property2']); diff --git a/tests/RouteProvider/RemovedEntityRouteProviderTest.php b/tests/RouteProvider/RemovedEntityRouteProviderTest.php index 42cbb41d..6b5f3da7 100644 --- a/tests/RouteProvider/RemovedEntityRouteProviderTest.php +++ b/tests/RouteProvider/RemovedEntityRouteProviderTest.php @@ -152,8 +152,9 @@ public function testExceptionIsThrownWhenEntityMetadataIsNotFound(): void $configurationLoader->method('load') ->willReturn(new Configuration([])); - $managerRegistry = self::createStub(ManagerRegistry::class); - $managerRegistry->method('getManagerForClass') + $managerRegistry = $this->createMock(ManagerRegistry::class); + $managerRegistry->expects(self::once()) + ->method('getManagerForClass') ->with(\stdClass::class) ->willReturn(null); @@ -241,24 +242,23 @@ private function createRouteProvider(array $configuration, bool $withExpressionL ->willReturn(new Configuration($configuration)); $classMetadata = self::createStub(ClassMetadata::class); - - $entityManager = self::createStub(EntityManagerInterface::class); - - $managerRegistry = self::createStub(ManagerRegistry::class); - $managerRegistry->method('getManagerForClass') - ->with(\stdClass::class) - ->willReturn($entityManager); - - $entityManager->method('getClassMetadata') - ->with(\stdClass::class) - ->willReturn($classMetadata); - $classMetadata->method('getFieldNames') ->willReturn(['foo', 'bar', 'baz']); - $classMetadata->method('getAssociationNames') ->willReturn([]); + $entityManager = $this->createMock(EntityManagerInterface::class); + $entityManager->expects(self::once()) + ->method('getClassMetadata') + ->with(\stdClass::class) + ->willReturn($classMetadata); + + $managerRegistry = $this->createMock(ManagerRegistry::class); + $managerRegistry->expects(self::once()) + ->method('getManagerForClass') + ->with(\stdClass::class) + ->willReturn($entityManager); + $expressionLanguage = null; if ($withExpressionLang) { $expressionLanguage = self::createStub(ExpressionLanguage::class);