From 5c30f988c956f927353e40a9518b88e406d694e6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 2 Nov 2024 15:26:57 +0700 Subject: [PATCH 1/5] Update to latest PHP 8.1 syntax Signed-off-by: Abdul Malik Ikhsan --- psalm-baseline.xml | 3 +-- src/AbstractFactory/ConfigAbstractFactory.php | 2 +- src/AbstractFactory/ReflectionBasedAbstractFactory.php | 2 +- src/AbstractPluginManager.php | 2 +- src/Exception/CyclicAliasException.php | 2 +- src/Exception/InvalidArgumentException.php | 5 ++--- test/Proxy/LazyServiceFactoryTest.php | 2 +- test/TestAsset/FactoryObject.php | 6 +----- test/TestAsset/InvokableObject.php | 5 +---- 9 files changed, 10 insertions(+), 19 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 086fcea0..b5241d95 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,12 +1,11 @@ - + - diff --git a/src/AbstractFactory/ConfigAbstractFactory.php b/src/AbstractFactory/ConfigAbstractFactory.php index 4629a6d2..5e6b7600 100644 --- a/src/AbstractFactory/ConfigAbstractFactory.php +++ b/src/AbstractFactory/ConfigAbstractFactory.php @@ -71,7 +71,7 @@ public function __invoke(ContainerInterface $container, string $requestedName, ? ); } - $arguments = array_map([$container, 'get'], $serviceDependencies); + $arguments = array_map($container->get(...), $serviceDependencies); return new $requestedName(...$arguments); } diff --git a/src/AbstractFactory/ReflectionBasedAbstractFactory.php b/src/AbstractFactory/ReflectionBasedAbstractFactory.php index 32e23cab..da5b9150 100644 --- a/src/AbstractFactory/ReflectionBasedAbstractFactory.php +++ b/src/AbstractFactory/ReflectionBasedAbstractFactory.php @@ -66,7 +66,7 @@ */ final class ReflectionBasedAbstractFactory implements AbstractFactoryInterface { - private ConstructorParameterResolverInterface $constructorParameterResolver; + private readonly ConstructorParameterResolverInterface $constructorParameterResolver; /** * Allows overriding the internal list of aliases. These should be of the diff --git a/src/AbstractPluginManager.php b/src/AbstractPluginManager.php index e284c280..3f099abd 100644 --- a/src/AbstractPluginManager.php +++ b/src/AbstractPluginManager.php @@ -117,7 +117,7 @@ abstract class AbstractPluginManager implements PluginManagerInterface */ protected array $shared = []; - private ServiceManager $plugins; + private readonly ServiceManager $plugins; /** * @param ServiceManagerConfiguration $config diff --git a/src/Exception/CyclicAliasException.php b/src/Exception/CyclicAliasException.php index 5c86025f..5a26d6ca 100644 --- a/src/Exception/CyclicAliasException.php +++ b/src/Exception/CyclicAliasException.php @@ -103,7 +103,7 @@ private static function printReferencesMap(array $aliases): string */ private static function printCycles(array $detectedCycles): string { - return "[\n" . implode("\n", array_map([self::class, 'printCycle'], $detectedCycles)) . "\n]"; + return "[\n" . implode("\n", array_map(self::printCycle(...), $detectedCycles)) . "\n]"; } /** diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 2cca6fd8..7a9c44a1 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -7,8 +7,7 @@ use InvalidArgumentException as SplInvalidArgumentException; use Laminas\ServiceManager\Initializer\InitializerInterface; -use function gettype; -use function is_object; +use function get_debug_type; use function sprintf; /** @@ -22,7 +21,7 @@ public static function fromInvalidInitializer(mixed $initializer): self 'An invalid initializer was registered. Expected a callable or an' . ' instance of "%s"; received "%s"', InitializerInterface::class, - is_object($initializer) ? $initializer::class : gettype($initializer) + get_debug_type($initializer) )); } } diff --git a/test/Proxy/LazyServiceFactoryTest.php b/test/Proxy/LazyServiceFactoryTest.php index 87d4541e..c1c40abd 100644 --- a/test/Proxy/LazyServiceFactoryTest.php +++ b/test/Proxy/LazyServiceFactoryTest.php @@ -91,7 +91,7 @@ static function ($className, $initializer) use ($expectedService, $proxy): MockO } ); - $result = $this->factory->__invoke($this->container, 'fooService', [$callback, 'callback']); + $result = $this->factory->__invoke($this->container, 'fooService', $callback->callback(...)); self::assertSame($expectedService, $result, 'service created not match the expected'); } diff --git a/test/TestAsset/FactoryObject.php b/test/TestAsset/FactoryObject.php index df072a3c..60ff2eed 100644 --- a/test/TestAsset/FactoryObject.php +++ b/test/TestAsset/FactoryObject.php @@ -6,14 +6,10 @@ final class FactoryObject { - /** @var mixed */ - public $dependency; - /** * @param mixed $dependency */ - public function __construct($dependency) + public function __construct(public $dependency) { - $this->dependency = $dependency; } } diff --git a/test/TestAsset/InvokableObject.php b/test/TestAsset/InvokableObject.php index b44cd484..6d53519c 100644 --- a/test/TestAsset/InvokableObject.php +++ b/test/TestAsset/InvokableObject.php @@ -6,11 +6,8 @@ class InvokableObject { - public array $options; - - public function __construct(array $options = []) + public function __construct(public array $options = []) { - $this->options = $options; } public function getOptions(): array From 791ea72f1e03357978336f936622fe43828584c7 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 4 Nov 2024 19:20:37 +0700 Subject: [PATCH 2/5] Update to use PHPUnit 10 syntax Signed-off-by: Abdul Malik Ikhsan --- .../ReflectionBasedAbstractFactoryTest.php | 7 +-- test/AbstractPluginManagerTest.php | 32 ++++------ .../AheadOfTimeFactoryCreatorCommandTest.php | 5 +- test/Command/FactoryCreatorCommandTest.php | 5 +- test/CommonServiceLocatorBehaviorsTrait.php | 59 ++++++++----------- test/Exception/CyclicAliasExceptionTest.php | 5 +- test/ServiceManagerTest.php | 21 +++---- .../AheadOfTimeFactoryCompilerTest.php | 11 ++-- test/Tool/ConfigDumperTest.php | 5 +- .../ConstructorParameterResolverTest.php | 5 +- 10 files changed, 62 insertions(+), 93 deletions(-) diff --git a/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php b/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php index 9ffedf4b..a915762b 100644 --- a/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php +++ b/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php @@ -9,6 +9,7 @@ use Laminas\ServiceManager\Exception\InvalidArgumentException; use Laminas\ServiceManager\Tool\ConstructorParameterResolver\ConstructorParameterResolverInterface; use LaminasTest\ServiceManager\AbstractFactory\TestAsset\ClassWithConstructorAcceptingAnyArgument; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -51,9 +52,7 @@ public static function invalidRequestNames(): array ]; } - /** - * @dataProvider invalidRequestNames - */ + #[DataProvider('invalidRequestNames')] public function testCanCreateReturnsFalseForUnsupportedRequestNames(string $requestedName): void { self::assertFalse($this->factory->canCreate($this->container, $requestedName)); @@ -87,8 +86,8 @@ public static function classNamesWithoutConstructorArguments(): array /** * @param class-string $className - * @dataProvider classNamesWithoutConstructorArguments */ + #[DataProvider('classNamesWithoutConstructorArguments')] public function testFactoryInstantiatesClassWithoutConstructorArguments(string $className): void { $instance = $this->factory->__invoke($this->container, $className); diff --git a/test/AbstractPluginManagerTest.php b/test/AbstractPluginManagerTest.php index 8a21518a..029d8d7d 100644 --- a/test/AbstractPluginManagerTest.php +++ b/test/AbstractPluginManagerTest.php @@ -15,6 +15,8 @@ use LaminasTest\ServiceManager\TestAsset\InvokableObject; use LaminasTest\ServiceManager\TestAsset\InvokableObjectPluginManager; use LaminasTest\ServiceManager\TestAsset\SimplePluginManager; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use stdClass; @@ -103,9 +105,7 @@ public static function shareByDefaultSettings(): array ]; } - /** - * @dataProvider shareByDefaultSettings - */ + #[DataProvider('shareByDefaultSettings')] public function testReturnsDiscreteInstancesIfOptionsAreProvidedRegardlessOfShareByDefaultSetting( bool $shareByDefault ): void { @@ -163,7 +163,7 @@ static function (ContainerInterface $container, string $name, callable $callback $instance = $pluginManager->get(stdClass::class); self::assertInstanceOf(stdClass::class, $instance); - self::assertTrue(isset($instance->option), 'Delegator-injected option was not found'); + self::assertObjectHasProperty('option', $instance, 'Delegator-injected option was not found'); self::assertEquals( $config['option'], $instance->option, @@ -185,10 +185,8 @@ public function testGetRaisesExceptionWhenNoFactoryIsResolved(): void $pluginManager->get('Some\Unknown\Service'); } - /** - * @group migration - * @group autoinvokable - */ + #[Group('migration')] + #[Group('autoinvokable')] public function testAutoInvokableServicesAreNotKnownBeforeRetrieval(): void { $pluginManager = new SimplePluginManager(new ServiceManager()); @@ -196,10 +194,8 @@ public function testAutoInvokableServicesAreNotKnownBeforeRetrieval(): void self::assertFalse($pluginManager->has(InvokableObject::class)); } - /** - * @group migration - * @group autoinvokable - */ + #[Group('migration')] + #[Group('autoinvokable')] public function testSupportsRetrievingAutoInvokableServicesByDefault(): void { $pluginManager = new SimplePluginManager(new ServiceManager()); @@ -208,10 +204,8 @@ public function testSupportsRetrievingAutoInvokableServicesByDefault(): void self::assertInstanceOf(InvokableObject::class, $invokable); } - /** - * @group migration - * @group autoinvokable - */ + #[Group('migration')] + #[Group('autoinvokable')] public function testPluginManagersMayOptOutOfSupportingAutoInvokableServices(): void { $pluginManager = new TestAsset\NonAutoInvokablePluginManager(new ServiceManager()); @@ -231,10 +225,8 @@ public function testPassingServiceInstanceViaConfigureShouldRaiseExceptionForInv ]); } - /** - * @group 79 - * @group 78 - */ + #[Group('79')] + #[Group('78')] public function testAbstractFactoryGetsCreationContext(): void { $serviceManager = new ServiceManager(); diff --git a/test/Command/AheadOfTimeFactoryCreatorCommandTest.php b/test/Command/AheadOfTimeFactoryCreatorCommandTest.php index 194c76fe..ad2d61a5 100644 --- a/test/Command/AheadOfTimeFactoryCreatorCommandTest.php +++ b/test/Command/AheadOfTimeFactoryCreatorCommandTest.php @@ -12,6 +12,7 @@ use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; use org\bovigo\vfs\vfsStreamFile; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; @@ -60,9 +61,7 @@ public static function invalidFactoryTargetPaths(): array ]; } - /** - * @dataProvider invalidFactoryTargetPaths - */ + #[DataProvider('invalidFactoryTargetPaths')] public function testEmitsErrorMessageIfFactoryTargetPathDoesNotMatchRequirements(string $factoryTargetPath): void { $command = new AheadOfTimeFactoryCreatorCommand([], $factoryTargetPath, $this->factoryCompiler); diff --git a/test/Command/FactoryCreatorCommandTest.php b/test/Command/FactoryCreatorCommandTest.php index ac29844b..840d8114 100644 --- a/test/Command/FactoryCreatorCommandTest.php +++ b/test/Command/FactoryCreatorCommandTest.php @@ -10,6 +10,7 @@ use Laminas\ServiceManager\Tool\FactoryCreatorInterface; use LaminasTest\ServiceManager\TestAsset\ObjectWithScalarDependency; use LaminasTest\ServiceManager\TestAsset\SimpleDependencyObject; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; @@ -55,9 +56,7 @@ public static function invalidArguments(): array ]; } - /** - * @dataProvider invalidArguments - */ + #[DataProvider('invalidArguments')] public function testEmitsErrorMessageIfArgumentIsNotAClass(string $argument): void { $this->input diff --git a/test/CommonServiceLocatorBehaviorsTrait.php b/test/CommonServiceLocatorBehaviorsTrait.php index 1aaabfd9..5688d9ed 100644 --- a/test/CommonServiceLocatorBehaviorsTrait.php +++ b/test/CommonServiceLocatorBehaviorsTrait.php @@ -24,6 +24,9 @@ use LaminasTest\ServiceManager\TestAsset\PassthroughDelegatorFactory; use LaminasTest\ServiceManager\TestAsset\SampleFactory; use LaminasTest\ServiceManager\TestAsset\SimpleAbstractFactory; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; @@ -381,9 +384,7 @@ public function testConfigureInvokablesTakePrecedenceOverFactories(): void self::assertInstanceOf(stdClass::class, $object); } - /** - * @group has - */ + #[Group('has')] public function testHasReturnsFalseIfServiceNotConfigured(): void { $serviceManager = self::createContainer([ @@ -395,9 +396,7 @@ public function testHasReturnsFalseIfServiceNotConfigured(): void self::assertFalse($serviceManager->has('Some\Made\Up\Entry')); } - /** - * @group has - */ + #[Group('has')] public function testHasReturnsTrueIfServiceIsConfigured(): void { $serviceManager = self::createContainer([ @@ -409,9 +408,7 @@ public function testHasReturnsTrueIfServiceIsConfigured(): void self::assertTrue($serviceManager->has(stdClass::class)); } - /** - * @group has - */ + #[Group('has')] public function testHasReturnsTrueIfFactoryIsConfigured(): void { $serviceManager = self::createContainer([ @@ -432,10 +429,8 @@ public static function abstractFactories(): array ]; } - /** - * @group has - * @dataProvider abstractFactories - */ + #[DataProvider('abstractFactories')] + #[Group('has')] public function testHasChecksAgainstAbstractFactories( AbstractFactoryInterface $abstractFactory, bool $expected, @@ -577,9 +572,9 @@ public function testGetRaisesExceptionWhenNoFactoryIsResolved(): void } /** - * @group mutation * @covers \Laminas\ServiceManager\ServiceManager::setAlias */ + #[Group('mutation')] public function testCanInjectAliases(): void { $container = self::createContainer([ @@ -599,9 +594,9 @@ public function testCanInjectAliases(): void } /** - * @group mutation * @covers \Laminas\ServiceManager\ServiceManager::setInvokableClass */ + #[Group('mutation')] public function testCanInjectInvokables(): void { $container = self::createContainer(); @@ -616,9 +611,9 @@ public function testCanInjectInvokables(): void } /** - * @group mutation * @covers \Laminas\ServiceManager\ServiceManager::setFactory */ + #[Group('mutation')] public function testCanInjectFactories(): void { $instance = new stdClass(); @@ -634,9 +629,9 @@ public function testCanInjectFactories(): void } /** - * @group mutation * @covers \Laminas\ServiceManager\ServiceManager::addAbstractFactory */ + #[Group('mutation')] public function testCanInjectAbstractFactories(): void { $container = self::createContainer(); @@ -650,9 +645,9 @@ public function testCanInjectAbstractFactories(): void } /** - * @group mutation * @covers \Laminas\ServiceManager\ServiceManager::addDelegator */ + #[Group('mutation')] public function testCanInjectDelegators(): void { $container = self::createContainer([ @@ -675,9 +670,9 @@ public function testCanInjectDelegators(): void } /** - * @group mutation * @covers \Laminas\ServiceManager\ServiceManager::addInitializer */ + #[Group('mutation')] public function testCanInjectInitializers(): void { $container = self::createContainer([ @@ -702,9 +697,9 @@ public function testCanInjectInitializers(): void } /** - * @group mutation * @covers \Laminas\ServiceManager\ServiceManager::setService */ + #[Group('mutation')] public function testCanInjectServices(): void { $container = self::createContainer(); @@ -714,9 +709,9 @@ public function testCanInjectServices(): void } /** - * @group mutation * @covers \Laminas\ServiceManager\ServiceManager::setShared */ + #[Group('mutation')] public function testCanInjectSharingRules(): void { $container = self::createContainer([ @@ -782,10 +777,8 @@ static function (): void { ]; } - /** - * @dataProvider methodsAffectedByOverrideSettings - * @group mutation - */ + #[DataProvider('methodsAffectedByOverrideSettings')] + #[Group('mutation')] public function testConfiguringInstanceRaisesExceptionIfAllowOverrideIsFalse(string $method, array $args): void { $container = self::createContainer(['services' => ['foo' => $this]]); @@ -794,9 +787,7 @@ public function testConfiguringInstanceRaisesExceptionIfAllowOverrideIsFalse(str $container->$method(...$args); } - /** - * @group mutation - */ + #[Group('mutation')] public function testAllowOverrideFlagIsFalseByDefault(): ContainerInterface { $container = self::createContainer(); @@ -806,10 +797,8 @@ public function testAllowOverrideFlagIsFalseByDefault(): ContainerInterface return $container; } - /** - * @group mutation - * @depends testAllowOverrideFlagIsFalseByDefault - */ + #[Depends('testAllowOverrideFlagIsFalseByDefault')] + #[Group('mutation')] public function testAllowOverrideFlagIsMutable(ServiceManager|AbstractPluginManager $container): void { $container->setAllowOverride(true); @@ -817,9 +806,7 @@ public function testAllowOverrideFlagIsMutable(ServiceManager|AbstractPluginMana self::assertTrue($container->getAllowOverride()); } - /** - * @group zendframework/zend-servicemanager#83 - */ + #[Group('zendframework/zend-servicemanager#83')] public function testCrashesOnCyclicAliases(): void { $this->expectException(CyclicAliasException::class); @@ -868,8 +855,8 @@ public function testCoverageDepthFirstTaggingOnRecursiveAliasDefinitions(): void * remain stable through the internal states. * * @param list $test - * @dataProvider provideConsistencyOverInternalStatesTests */ + #[DataProvider('provideConsistencyOverInternalStatesTests')] public function testConsistencyOverInternalStates( ContainerInterface $smTemplate, string $name, diff --git a/test/Exception/CyclicAliasExceptionTest.php b/test/Exception/CyclicAliasExceptionTest.php index a4c5a0cc..ca81294d 100644 --- a/test/Exception/CyclicAliasExceptionTest.php +++ b/test/Exception/CyclicAliasExceptionTest.php @@ -5,6 +5,7 @@ namespace LaminasTest\ServiceManager\Exception; use Laminas\ServiceManager\Exception\CyclicAliasException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -13,10 +14,10 @@ final class CyclicAliasExceptionTest extends TestCase { /** - * @dataProvider cyclicAliasProvider * @param string $alias, conflicting alias key * @param array $aliases */ + #[DataProvider('cyclicAliasProvider')] public function testFromCyclicAlias(string $alias, array $aliases, string $expectedMessage): void { $exception = CyclicAliasException::fromCyclicAlias($alias, $aliases); @@ -96,9 +97,9 @@ public static function cyclicAliasProvider(): array } /** - * @dataProvider aliasesProvider * @param array $aliases */ + #[DataProvider('aliasesProvider')] public function testFromAliasesMap(array $aliases, string $expectedMessage): void { $exception = CyclicAliasException::fromAliasesMap($aliases); diff --git a/test/ServiceManagerTest.php b/test/ServiceManagerTest.php index 16843e9c..3468d46f 100644 --- a/test/ServiceManagerTest.php +++ b/test/ServiceManagerTest.php @@ -12,6 +12,9 @@ use Laminas\ServiceManager\ServiceManager; use LaminasTest\ServiceManager\TestAsset\InvokableObject; use LaminasTest\ServiceManager\TestAsset\SimpleServiceManager; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use ReflectionProperty; @@ -109,7 +112,7 @@ static function (ContainerInterface $container, string $name, callable $callback $instance = $serviceManager->get(stdClass::class); self::assertInstanceOf(stdClass::class, $instance); - self::assertTrue(isset($instance->option), 'Delegator-injected option was not found'); + self::assertObjectHasProperty('option', $instance, 'Delegator-injected option was not found'); self::assertEquals( $config['option'], $instance->option, @@ -178,9 +181,7 @@ public static function shareProvider(): array ]; } - /** - * @dataProvider shareProvider - */ + #[DataProvider('shareProvider')] public function testShareability( bool $sharedByDefault, bool $serviceShared, @@ -253,9 +254,7 @@ public function testMapsNonSymmetricInvokablesAsAliasPlusInvokableFactory(): voi ); } - /** - * @depends testMapsNonSymmetricInvokablesAsAliasPlusInvokableFactory - */ + #[Depends('testMapsNonSymmetricInvokablesAsAliasPlusInvokableFactory')] public function testSharedServicesReferencingInvokableAliasShouldBeHonored(): void { $config = [ @@ -314,9 +313,7 @@ public function testAliasToAnExplicitServiceShouldWork(): void self::assertSame($service, $alias); } - /** - * @depends testAliasToAnExplicitServiceShouldWork - */ + #[Depends('testAliasToAnExplicitServiceShouldWork')] public function testSetAliasShouldWorkWithRecursiveAlias(): void { $config = [ @@ -507,8 +504,8 @@ static function (object $service) use (&$initializerTwoCalled): object { * @param ServiceManagerConfiguration $config * @param non-empty-string $serviceName * @param non-empty-string $alias - * @dataProvider aliasedServices */ + #[DataProvider('aliasedServices')] public function testWontShareServiceWhenRequestedByAlias(array $config, string $serviceName, string $alias): void { $serviceManager = new ServiceManager($config); @@ -621,9 +618,9 @@ public function testHasVerifiesAliasesBeforeUsingAbstractFactories(): void } /** - * @group mutation * @covers \Laminas\ServiceManager\ServiceManager::mapLazyService */ + #[Group('mutation')] public function testCanMapLazyServices(): void { $container = self::createContainer(); diff --git a/test/Tool/AheadOfTimeFactoryCompiler/AheadOfTimeFactoryCompilerTest.php b/test/Tool/AheadOfTimeFactoryCompiler/AheadOfTimeFactoryCompilerTest.php index e8f5427f..e5d4fc11 100644 --- a/test/Tool/AheadOfTimeFactoryCompiler/AheadOfTimeFactoryCompilerTest.php +++ b/test/Tool/AheadOfTimeFactoryCompiler/AheadOfTimeFactoryCompilerTest.php @@ -13,6 +13,7 @@ use LaminasTest\ServiceManager\TestAsset\SimpleDependencyObject; use LaminasTest\ServiceManager\Tool\AheadOfTimeFactoryCompiler\TestAsset\WhateverEnum; use LaminasTest\ServiceManager\Tool\AheadOfTimeFactoryCompiler\TestAsset\WhateverTrait; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use stdClass; @@ -56,9 +57,7 @@ public static function configurationsWithoutRegisteredServices(): array ]; } - /** - * @dataProvider configurationsWithoutRegisteredServices - */ + #[DataProvider('configurationsWithoutRegisteredServices')] public function testCanHandleConfigWithoutServicesRegisteredWithReflectionBasedAbstractFactory(array $config): void { $this->factoryCreator @@ -126,10 +125,8 @@ public static function nonClassReferencingServiceNamesPhp81Upwards(): array ]; } - /** - * @dataProvider nonClassReferencingServiceNames - * @dataProvider nonClassReferencingServiceNamesPhp81Upwards - */ + #[DataProvider('nonClassReferencingServiceNames')] + #[DataProvider('nonClassReferencingServiceNamesPhp81Upwards')] public function testWillRaiseExceptionWhenFactoryIsUsedWithNonClassReferencingService(string $serviceName): void { $config = [ diff --git a/test/Tool/ConfigDumperTest.php b/test/Tool/ConfigDumperTest.php index 3ec0da15..4704afcf 100644 --- a/test/Tool/ConfigDumperTest.php +++ b/test/Tool/ConfigDumperTest.php @@ -16,6 +16,7 @@ use LaminasTest\ServiceManager\TestAsset\ObjectWithScalarDependency; use LaminasTest\ServiceManager\TestAsset\SecondComplexDependencyObject; use LaminasTest\ServiceManager\TestAsset\SimpleDependencyObject; +use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -304,9 +305,7 @@ public function testCreateFactoryMappingsFromConfigWithWorkingConfig(): void self::assertSame($expectedConfig, $this->dumper->createFactoryMappingsFromConfig($config)); } - /** - * @depends testCreateDependencyConfigSimpleDependencyReturnsCorrectly - */ + #[Depends('testCreateDependencyConfigSimpleDependencyReturnsCorrectly')] public function testDumpConfigFileReturnsContentsForConfigFileUsingUsingClassNotationAndShortArrays( array $config ): void { diff --git a/test/Tool/ConstructorParameterResolver/ConstructorParameterResolverTest.php b/test/Tool/ConstructorParameterResolver/ConstructorParameterResolverTest.php index 2974bbd6..343fa4ed 100644 --- a/test/Tool/ConstructorParameterResolver/ConstructorParameterResolverTest.php +++ b/test/Tool/ConstructorParameterResolver/ConstructorParameterResolverTest.php @@ -21,6 +21,7 @@ use LaminasTest\ServiceManager\AbstractFactory\TestAsset\ValidatorPluginManager; use LaminasTest\ServiceManager\TestAsset\ClassDependingOnAnInterface; use LaminasTest\ServiceManager\TestAsset\ClassWithConstructorWithOnlyOptionalArguments; +use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -206,9 +207,7 @@ public function testResolvesTypeHintsForServicesToWellKnownServiceNames(): void self::assertSame($validators, $parameters[0]); } - /** - * @depends testWillResolveConstructorArgumentsAccordingToTheirPosition - */ + #[Depends('testWillResolveConstructorArgumentsAccordingToTheirPosition')] public function testResolvesAMixOfParameterTypes(): void { $this->container From 858823d8c22454c9da7c0d2941c51a2682ed7445 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 4 Nov 2024 19:22:22 +0700 Subject: [PATCH 3/5] Regenerate psalm baseline Signed-off-by: Abdul Malik Ikhsan --- psalm-baseline.xml | 48 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index b5241d95..315f54b0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -117,19 +117,35 @@ + + + + + + - - - + + + + + + + + + + + + + @@ -153,12 +169,26 @@ + + + + + + + + + + + + + + @@ -190,14 +220,13 @@ - - - + + @@ -230,6 +259,13 @@ + + + + + + + From f17d94e164040c20acc52f6f76da8bff6bc34f2f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 4 Nov 2024 19:26:09 +0700 Subject: [PATCH 4/5] Migrate @ covers as well Signed-off-by: Abdul Malik Ikhsan --- psalm-baseline.xml | 20 +++++++++++++++++++ .../ConfigAbstractFactoryTest.php | 5 ++--- .../ReflectionBasedAbstractFactoryTest.php | 5 ++--- test/AbstractPluginManagerTest.php | 7 ++----- .../AheadOfTimeFactoryCreatorCommandTest.php | 4 +--- test/Command/ConfigDumperCommandTest.php | 4 +--- test/Command/FactoryCreatorCommandTest.php | 4 +--- test/Exception/CyclicAliasExceptionTest.php | 5 ++--- test/Factory/InvokableFactoryTest.php | 5 ++--- test/LazyServiceIntegrationTest.php | 13 +----------- test/Proxy/LazyServiceFactoryTest.php | 5 ++--- test/ServiceManagerTest.php | 10 ++-------- test/Tool/ConfigDumperTest.php | 4 +--- test/Tool/FactoryCreatorTest.php | 4 +--- 14 files changed, 40 insertions(+), 55 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 315f54b0..a5d470c8 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -135,16 +135,25 @@ + + + + + + + + + @@ -203,6 +212,9 @@ + + + @@ -267,8 +279,16 @@ + + + + + + + + diff --git a/test/AbstractFactory/ConfigAbstractFactoryTest.php b/test/AbstractFactory/ConfigAbstractFactoryTest.php index 18710fac..c7012a4d 100644 --- a/test/AbstractFactory/ConfigAbstractFactoryTest.php +++ b/test/AbstractFactory/ConfigAbstractFactoryTest.php @@ -12,11 +12,10 @@ use LaminasTest\ServiceManager\TestAsset\InvokableObject; use LaminasTest\ServiceManager\TestAsset\SecondComplexDependencyObject; use LaminasTest\ServiceManager\TestAsset\SimpleDependencyObject; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory - */ +#[CoversClass(ConfigAbstractFactory::class)] final class ConfigAbstractFactoryTest extends TestCase { private ConfigAbstractFactory $abstractFactory; diff --git a/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php b/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php index a915762b..cfeadc40 100644 --- a/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php +++ b/test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php @@ -9,15 +9,14 @@ use Laminas\ServiceManager\Exception\InvalidArgumentException; use Laminas\ServiceManager\Tool\ConstructorParameterResolver\ConstructorParameterResolverInterface; use LaminasTest\ServiceManager\AbstractFactory\TestAsset\ClassWithConstructorAcceptingAnyArgument; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use stdClass; -/** - * @covers \Laminas\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory - */ +#[CoversClass(ReflectionBasedAbstractFactory::class)] final class ReflectionBasedAbstractFactoryTest extends TestCase { /** @var ContainerInterface&MockObject */ diff --git a/test/AbstractPluginManagerTest.php b/test/AbstractPluginManagerTest.php index 029d8d7d..7204df2d 100644 --- a/test/AbstractPluginManagerTest.php +++ b/test/AbstractPluginManagerTest.php @@ -15,15 +15,14 @@ use LaminasTest\ServiceManager\TestAsset\InvokableObject; use LaminasTest\ServiceManager\TestAsset\InvokableObjectPluginManager; use LaminasTest\ServiceManager\TestAsset\SimplePluginManager; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use stdClass; -/** - * @covers \Laminas\ServiceManager\AbstractPluginManager - */ +#[CoversClass(AbstractPluginManager::class)] final class AbstractPluginManagerTest extends TestCase { use CommonServiceLocatorBehaviorsTrait; @@ -174,8 +173,6 @@ static function (ContainerInterface $container, string $name, callable $callback /** * Overrides the method in the CommonServiceLocatorBehaviorsTrait, due to behavior differences. - * - * @covers \Laminas\ServiceManager\AbstractPluginManager::get */ public function testGetRaisesExceptionWhenNoFactoryIsResolved(): void { diff --git a/test/Command/AheadOfTimeFactoryCreatorCommandTest.php b/test/Command/AheadOfTimeFactoryCreatorCommandTest.php index ad2d61a5..d80e7012 100644 --- a/test/Command/AheadOfTimeFactoryCreatorCommandTest.php +++ b/test/Command/AheadOfTimeFactoryCreatorCommandTest.php @@ -22,9 +22,7 @@ use function file_get_contents; use function sprintf; -/** - * @covers \Laminas\ServiceManager\Command\AheadOfTimeFactoryCreatorCommand - */ +#[CoversClass(AheadOfTimeFactoryCreatorCommand::class)] final class AheadOfTimeFactoryCreatorCommandTest extends TestCase { /** @var MockObject&InputInterface */ diff --git a/test/Command/ConfigDumperCommandTest.php b/test/Command/ConfigDumperCommandTest.php index 1151066d..9876e024 100644 --- a/test/Command/ConfigDumperCommandTest.php +++ b/test/Command/ConfigDumperCommandTest.php @@ -20,9 +20,7 @@ use function realpath; use function sprintf; -/** - * @covers \Laminas\ServiceManager\Command\ConfigDumperCommand - */ +#[CoversClass(ConfigDumperCommand::class)] final class ConfigDumperCommandTest extends TestCase { private vfsStreamDirectory $configDir; diff --git a/test/Command/FactoryCreatorCommandTest.php b/test/Command/FactoryCreatorCommandTest.php index 840d8114..d47466f7 100644 --- a/test/Command/FactoryCreatorCommandTest.php +++ b/test/Command/FactoryCreatorCommandTest.php @@ -19,9 +19,7 @@ use function file_get_contents; use function sprintf; -/** - * @covers \Laminas\ServiceManager\Command\FactoryCreatorCommand - */ +#[CoversClass(FactoryCreatorCommand::class)] final class FactoryCreatorCommandTest extends TestCase { private FactoryCreatorCommand $command; diff --git a/test/Exception/CyclicAliasExceptionTest.php b/test/Exception/CyclicAliasExceptionTest.php index ca81294d..4fc87623 100644 --- a/test/Exception/CyclicAliasExceptionTest.php +++ b/test/Exception/CyclicAliasExceptionTest.php @@ -5,12 +5,11 @@ namespace LaminasTest\ServiceManager\Exception; use Laminas\ServiceManager\Exception\CyclicAliasException; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \Laminas\ServiceManager\Exception\CyclicAliasException - */ +#[CoversClass(CyclicAliasException::class)] final class CyclicAliasExceptionTest extends TestCase { /** diff --git a/test/Factory/InvokableFactoryTest.php b/test/Factory/InvokableFactoryTest.php index 56aeae3e..e384ec1c 100644 --- a/test/Factory/InvokableFactoryTest.php +++ b/test/Factory/InvokableFactoryTest.php @@ -6,12 +6,11 @@ use Laminas\ServiceManager\Factory\InvokableFactory; use LaminasTest\ServiceManager\TestAsset\InvokableObject; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; -/** - * @covers \Laminas\ServiceManager\Factory\InvokableFactory - */ +#[CoversClass(InvokableFactory::class)] final class InvokableFactoryTest extends TestCase { public function testCanCreateObject(): void diff --git a/test/LazyServiceIntegrationTest.php b/test/LazyServiceIntegrationTest.php index 2bc09dde..2b7e3725 100644 --- a/test/LazyServiceIntegrationTest.php +++ b/test/LazyServiceIntegrationTest.php @@ -33,9 +33,7 @@ use function sys_get_temp_dir; use function unlink; -/** - * @covers \Laminas\ServiceManager\ServiceManager - */ +#[CoversClass(ServiceManager::class)] final class LazyServiceIntegrationTest extends TestCase { /** @var non-empty-string */ @@ -116,9 +114,6 @@ private function assertProxyFileWritten(string $message = ''): void self::assertNotEquals([], iterator_to_array($this->listProxyFiles()), $message); } - /** - * @covers \Laminas\ServiceManager\ServiceManager::createLazyServiceDelegatorFactory - */ public function testCanUseLazyServiceFactoryFactoryToCreateLazyServiceFactoryToActAsDelegatorToCreateLazyService(): void { $config = [ @@ -169,9 +164,6 @@ public function testCanUseLazyServiceFactoryFactoryToCreateLazyServiceFactoryToA self::assertCount(1, $proxyAutoloadFunctions, 'Only 1 proxy autoloader should be registered'); } - /** - * @covers \Laminas\ServiceManager\ServiceManager::createLazyServiceDelegatorFactory - */ public function testMissingClassMapRaisesExceptionOnAttemptToRetrieveLazyService(): void { $config = [ @@ -190,9 +182,6 @@ public function testMissingClassMapRaisesExceptionOnAttemptToRetrieveLazyService $container->get(InvokableObject::class); } - /** - * @covers \Laminas\ServiceManager\ServiceManager::createLazyServiceDelegatorFactory - */ public function testWillNotGenerateProxyClassFilesByDefault(): void { $config = [ diff --git a/test/Proxy/LazyServiceFactoryTest.php b/test/Proxy/LazyServiceFactoryTest.php index c1c40abd..582f135f 100644 --- a/test/Proxy/LazyServiceFactoryTest.php +++ b/test/Proxy/LazyServiceFactoryTest.php @@ -8,6 +8,7 @@ use Laminas\ServiceManager\Factory\DelegatorFactoryInterface; use Laminas\ServiceManager\Proxy\LazyServiceFactory; use LaminasTest\ServiceManager\TestAsset\ClassWithCallbackMethod; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ProxyManager\Factory\LazyLoadingValueHolderFactory; @@ -15,9 +16,7 @@ use ProxyManager\Proxy\VirtualProxyInterface; use Psr\Container\ContainerInterface; -/** - * @covers \Laminas\ServiceManager\Proxy\LazyServiceFactory - */ +#[CoversClass(LazyServiceFactory::class)] final class LazyServiceFactoryTest extends TestCase { private LazyServiceFactory $factory; diff --git a/test/ServiceManagerTest.php b/test/ServiceManagerTest.php index 3468d46f..d2b8198d 100644 --- a/test/ServiceManagerTest.php +++ b/test/ServiceManagerTest.php @@ -12,6 +12,7 @@ use Laminas\ServiceManager\ServiceManager; use LaminasTest\ServiceManager\TestAsset\InvokableObject; use LaminasTest\ServiceManager\TestAsset\SimpleServiceManager; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\Attributes\Group; @@ -21,9 +22,9 @@ use stdClass; /** - * @covers \Laminas\ServiceManager\ServiceManager * @psalm-import-type ServiceManagerConfiguration from ServiceManager */ +#[CoversClass(ServiceManager::class)] final class ServiceManagerTest extends TestCase { use CommonServiceLocatorBehaviorsTrait; @@ -80,10 +81,6 @@ public function testConfigurationTakesPrecedenceWhenMerged(): void self::assertSame($service, $serviceFromServiceManager); } - /** - * @covers \Laminas\ServiceManager\ServiceManager::doCreate - * @covers \Laminas\ServiceManager\ServiceManager::createDelegatorFromName - */ public function testCanWrapCreationInDelegators(): void { $config = [ @@ -617,9 +614,6 @@ public function testHasVerifiesAliasesBeforeUsingAbstractFactories(): void self::assertTrue($serviceManager->has('config')); } - /** - * @covers \Laminas\ServiceManager\ServiceManager::mapLazyService - */ #[Group('mutation')] public function testCanMapLazyServices(): void { diff --git a/test/Tool/ConfigDumperTest.php b/test/Tool/ConfigDumperTest.php index 4704afcf..e7c1df24 100644 --- a/test/Tool/ConfigDumperTest.php +++ b/test/Tool/ConfigDumperTest.php @@ -25,9 +25,7 @@ use function tempnam; use function unlink; -/** - * @covers \Laminas\ServiceManager\Tool\ConfigDumper - */ +#[CoversClass(ConfigDumper::class)] final class ConfigDumperTest extends TestCase { private ConfigDumper $dumper; diff --git a/test/Tool/FactoryCreatorTest.php b/test/Tool/FactoryCreatorTest.php index 2efde2b6..48caa862 100644 --- a/test/Tool/FactoryCreatorTest.php +++ b/test/Tool/FactoryCreatorTest.php @@ -25,9 +25,7 @@ use const PHP_EOL; -/** - * @covers \Laminas\ServiceManager\Tool\FactoryCreator - */ +#[CoversClass(FactoryCreator::class)] final class FactoryCreatorTest extends TestCase { private FactoryCreator $factoryCreator; From 7a4e3643d77ecceedde3191d7e0b1aaba74d0db9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 5 Nov 2024 04:17:34 +0700 Subject: [PATCH 5/5] Add missing CoversClass to use statement Signed-off-by: Abdul Malik Ikhsan --- psalm-baseline.xml | 20 ------------------- .../AheadOfTimeFactoryCreatorCommandTest.php | 1 + test/Command/ConfigDumperCommandTest.php | 1 + test/Command/FactoryCreatorCommandTest.php | 1 + test/LazyServiceIntegrationTest.php | 1 + test/Tool/ConfigDumperTest.php | 1 + test/Tool/FactoryCreatorTest.php | 1 + 7 files changed, 6 insertions(+), 20 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a5d470c8..315f54b0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -135,25 +135,16 @@ - - - - - - - - - @@ -212,9 +203,6 @@ - - - @@ -279,16 +267,8 @@ - - - - - - - - diff --git a/test/Command/AheadOfTimeFactoryCreatorCommandTest.php b/test/Command/AheadOfTimeFactoryCreatorCommandTest.php index d80e7012..db875946 100644 --- a/test/Command/AheadOfTimeFactoryCreatorCommandTest.php +++ b/test/Command/AheadOfTimeFactoryCreatorCommandTest.php @@ -12,6 +12,7 @@ use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; use org\bovigo\vfs\vfsStreamFile; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/test/Command/ConfigDumperCommandTest.php b/test/Command/ConfigDumperCommandTest.php index 9876e024..fbd0f281 100644 --- a/test/Command/ConfigDumperCommandTest.php +++ b/test/Command/ConfigDumperCommandTest.php @@ -11,6 +11,7 @@ use LaminasTest\ServiceManager\TestAsset\SimpleDependencyObject; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; diff --git a/test/Command/FactoryCreatorCommandTest.php b/test/Command/FactoryCreatorCommandTest.php index d47466f7..dc37785b 100644 --- a/test/Command/FactoryCreatorCommandTest.php +++ b/test/Command/FactoryCreatorCommandTest.php @@ -10,6 +10,7 @@ use Laminas\ServiceManager\Tool\FactoryCreatorInterface; use LaminasTest\ServiceManager\TestAsset\ObjectWithScalarDependency; use LaminasTest\ServiceManager\TestAsset\SimpleDependencyObject; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/test/LazyServiceIntegrationTest.php b/test/LazyServiceIntegrationTest.php index 2b7e3725..f019128e 100644 --- a/test/LazyServiceIntegrationTest.php +++ b/test/LazyServiceIntegrationTest.php @@ -11,6 +11,7 @@ use Laminas\ServiceManager\Proxy\LazyServiceFactory; use Laminas\ServiceManager\ServiceManager; use LaminasTest\ServiceManager\TestAsset\InvokableObject; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use ProxyManager\Autoloader\AutoloaderInterface; use RecursiveDirectoryIterator; diff --git a/test/Tool/ConfigDumperTest.php b/test/Tool/ConfigDumperTest.php index e7c1df24..b5e8fa92 100644 --- a/test/Tool/ConfigDumperTest.php +++ b/test/Tool/ConfigDumperTest.php @@ -16,6 +16,7 @@ use LaminasTest\ServiceManager\TestAsset\ObjectWithScalarDependency; use LaminasTest\ServiceManager\TestAsset\SecondComplexDependencyObject; use LaminasTest\ServiceManager\TestAsset\SimpleDependencyObject; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; diff --git a/test/Tool/FactoryCreatorTest.php b/test/Tool/FactoryCreatorTest.php index 48caa862..af40d779 100644 --- a/test/Tool/FactoryCreatorTest.php +++ b/test/Tool/FactoryCreatorTest.php @@ -11,6 +11,7 @@ use LaminasTest\ServiceManager\TestAsset\InvokableObject; use LaminasTest\ServiceManager\TestAsset\SecondComplexDependencyObject; use LaminasTest\ServiceManager\TestAsset\SimpleDependencyObject; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface;