diff --git a/tests/Cache/PropertyResolver/AssociationResolverTestCase.php b/tests/Cache/PropertyResolver/AssociationResolverTestCase.php index e4f43d19..12fb7129 100644 --- a/tests/Cache/PropertyResolver/AssociationResolverTestCase.php +++ b/tests/Cache/PropertyResolver/AssociationResolverTestCase.php @@ -33,8 +33,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( @@ -126,8 +127,9 @@ public function testFieldNotAssociation(): void ), ); - $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/ExpressionLanguage/InverseRelationExpressionTransformerTest.php b/tests/Cache/PropertyResolver/ExpressionLanguage/InverseRelationExpressionTransformerTest.php index f52f1c9f..5c0c5890 100644 --- a/tests/Cache/PropertyResolver/ExpressionLanguage/InverseRelationExpressionTransformerTest.php +++ b/tests/Cache/PropertyResolver/ExpressionLanguage/InverseRelationExpressionTransformerTest.php @@ -20,8 +20,9 @@ final class InverseRelationExpressionTransformerTest extends TestCase #[TestWith(['false', PropertyReadInfo::TYPE_METHOD, 'isBar', 'obj.isBar() !== null ? (obj.isBar().firstName~"-"~obj.isBar().lastName) : false'])] public function testTransform(string $fallback, string $readInfoType, string $readInfoName, string $expectedExpression): void { - $extractor = self::createStub(PropertyReadInfoExtractorInterface::class); - $extractor->method('getReadInfo') + $extractor = $this->createMock(PropertyReadInfoExtractorInterface::class); + $extractor->expects(self::once()) + ->method('getReadInfo') ->with(\stdClass::class, 'prop') ->willReturn( new PropertyReadInfo( @@ -42,8 +43,9 @@ public function testTransform(string $fallback, string $readInfoType, string $re public function testExceptionIsThrownWhenPropertyIsNotAccessible(): void { - $extractor = self::createStub(PropertyReadInfoExtractorInterface::class); - $extractor->method('getReadInfo') + $extractor = $this->createMock(PropertyReadInfoExtractorInterface::class); + $extractor->expects(self::once()) + ->method('getReadInfo') ->with(\stdClass::class, 'prop') ->willReturn(null); diff --git a/tests/Cache/PropertyResolver/InverseValuesBuildersTest.php b/tests/Cache/PropertyResolver/InverseValuesBuildersTest.php index 6e0ebc11..f9904f65 100644 --- a/tests/Cache/PropertyResolver/InverseValuesBuildersTest.php +++ b/tests/Cache/PropertyResolver/InverseValuesBuildersTest.php @@ -29,8 +29,9 @@ final class InverseValuesBuildersTest extends TestCase { public function testBuild(): void { - $extractor = self::createStub(PropertyReadInfoExtractorInterface::class); - $extractor->method('getReadInfo') + $extractor = $this->createMock(PropertyReadInfoExtractorInterface::class); + $extractor->expects(self::once()) + ->method('getReadInfo') ->with(\stdClass::class, 'association') ->willReturn( new PropertyReadInfo( 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/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 c82b5266..61ea781a 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,14 +148,15 @@ 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; }); $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); @@ -300,7 +303,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 +341,7 @@ public function testWithMissingRouteParams( ): void { $routeMetadataProvider = self::createStub(RouteMetadataProviderInterface::class); $routeMetadataProvider->method('provide') - ->willReturnCallback(function () use ($routeMetadata) { + ->willReturnCallback(static function () use ($routeMetadata) { yield $routeMetadata; }); @@ -491,7 +494,7 @@ public function testExceptionIsThrownOnInvalidRouteParamsExpression(string $expr { $routeMetadataProvider = self::createStub(RouteMetadataProviderInterface::class); $routeMetadataProvider->method('provide') - ->willReturnCallback(function () use ($expression): iterable { + ->willReturnCallback(static function () use ($expression): iterable { yield new RouteMetadata( routeName: 'foo', route: new Route('/{foo}'), @@ -514,7 +517,7 @@ class: 'FooEntity', public function getFunctions(): array { return [ - new ExpressionFunction('valid_function', function () {}, function () {}), + new ExpressionFunction('valid_function', static function () {}, static function () {}), ]; } }, @@ -533,7 +536,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}'), @@ -556,7 +559,7 @@ class: 'FooEntity', public function getFunctions(): array { return [ - new ExpressionFunction('valid_function', function () {}, function () {}), + new ExpressionFunction('valid_function', static function () {}, static function () {}), ]; } }, 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);