Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/4.3.x' into 3.23.x-merge-up-in…
Browse files Browse the repository at this point in the history
…to-4.0.x_4XHhBTeB

# Conflicts:
#	psalm-baseline.xml
  • Loading branch information
gsteel committed Nov 4, 2024
2 parents be73fda + e61572c commit d41c0a6
Show file tree
Hide file tree
Showing 24 changed files with 140 additions and 168 deletions.
46 changes: 43 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<files psalm-version="5.23.1@8471a896ccea3526b26d082f4461eeea467f10a4">
<file src="src/AbstractFactory/ConfigAbstractFactory.php">
<InvalidStringClass>
<code><![CDATA[new $requestedName(...$arguments)]]></code>
</InvalidStringClass>
<MixedArgument>
<code><![CDATA[$serviceDependencies]]></code>
<code><![CDATA[$serviceDependencies]]></code>
</MixedArgument>
<MixedArrayAccess>
<code><![CDATA[$config[self::class]]]></code>
Expand All @@ -27,7 +26,6 @@
</file>
<file src="src/Exception/CyclicAliasException.php">
<InvalidArgument>
<code><![CDATA[[self::class, 'printCycle']]]></code>
<code><![CDATA[self::deDuplicateDetectedCycles($detectedCycles)]]></code>
</InvalidArgument>
<PossiblyFalseOperand>
Expand Down Expand Up @@ -119,16 +117,35 @@
<code><![CDATA[$key]]></code>
</PossiblyNullArgument>
</file>
<file src="test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php">
<PossiblyUnusedMethod>
<code><![CDATA[classNamesWithoutConstructorArguments]]></code>
<code><![CDATA[invalidRequestNames]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/AbstractPluginManagerTest.php">
<MixedPropertyAssignment>
<code><![CDATA[$instance]]></code>
</MixedPropertyAssignment>
<PossiblyUnusedMethod>
<code><![CDATA[shareByDefaultSettings]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/Command/AheadOfTimeFactoryCreatorCommandTest.php">
<PossiblyUnusedMethod>
<code><![CDATA[invalidFactoryTargetPaths]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/Command/ConfigDumperCommandTest.php">
<PossiblyUnusedMethod>
<code><![CDATA[ignoreUnresolvedArguments]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/Command/FactoryCreatorCommandTest.php">
<PossiblyUnusedMethod>
<code><![CDATA[invalidArguments]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/CommonServiceLocatorBehaviorsTrait.php">
<MissingClosureParamType>
<code><![CDATA[$callback]]></code>
Expand All @@ -152,12 +169,26 @@
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$object['get'][0]]]></code>
</PossiblyUndefinedArrayOffset>
<PossiblyUnusedMethod>
<code><![CDATA[abstractFactories]]></code>
<code><![CDATA[abstractFactories]]></code>
<code><![CDATA[methodsAffectedByOverrideSettings]]></code>
<code><![CDATA[methodsAffectedByOverrideSettings]]></code>
<code><![CDATA[provideConsistencyOverInternalStatesTests]]></code>
<code><![CDATA[provideConsistencyOverInternalStatesTests]]></code>
</PossiblyUnusedMethod>
<UnusedClosureParam>
<code><![CDATA[$container]]></code>
<code><![CDATA[$options]]></code>
<code><![CDATA[$requestedName]]></code>
</UnusedClosureParam>
</file>
<file src="test/Exception/CyclicAliasExceptionTest.php">
<PossiblyUnusedMethod>
<code><![CDATA[aliasesProvider]]></code>
<code><![CDATA[cyclicAliasProvider]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/LazyServiceIntegrationTest.php">
<InvalidReturnStatement>
<code><![CDATA[array_filter(spl_autoload_functions(), $filter)]]></code>
Expand Down Expand Up @@ -193,7 +224,9 @@
<code><![CDATA[$inc]]></code>
</MixedOperand>
<PossiblyUnusedMethod>
<code><![CDATA[aliasedServices]]></code>
<code><![CDATA[sampleFactory]]></code>
<code><![CDATA[shareProvider]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/StaticAnalysis/CallablePluginManager.php">
Expand Down Expand Up @@ -226,6 +259,13 @@
<code><![CDATA[UnionPluginManager]]></code>
</UnusedClass>
</file>
<file src="test/Tool/AheadOfTimeFactoryCompiler/AheadOfTimeFactoryCompilerTest.php">
<PossiblyUnusedMethod>
<code><![CDATA[configurationsWithoutRegisteredServices]]></code>
<code><![CDATA[nonClassReferencingServiceNames]]></code>
<code><![CDATA[nonClassReferencingServiceNamesPhp81Upwards]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/Tool/ConfigDumperTest.php">
<UnresolvableInclude>
<code><![CDATA[include $file]]></code>
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractFactory/ConfigAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractFactory/ReflectionBasedAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ abstract class AbstractPluginManager implements PluginManagerInterface
*/
protected array $shared = [];

private ServiceManager $plugins;
private readonly ServiceManager $plugins;

/**
* @param ServiceManagerConfiguration $config
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/CyclicAliasException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]";
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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)
));
}
}
5 changes: 2 additions & 3 deletions test/AbstractFactory/ConfigAbstractFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions test/AbstractFactory/ReflectionBasedAbstractFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +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 */
Expand Down Expand Up @@ -51,9 +51,7 @@ public static function invalidRequestNames(): array
];
}

/**
* @dataProvider invalidRequestNames
*/
#[DataProvider('invalidRequestNames')]
public function testCanCreateReturnsFalseForUnsupportedRequestNames(string $requestedName): void
{
self::assertFalse($this->factory->canCreate($this->container, $requestedName));
Expand Down Expand Up @@ -87,8 +85,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);
Expand Down
39 changes: 14 additions & 25 deletions test/AbstractPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +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;
Expand Down Expand Up @@ -104,9 +105,7 @@ public static function shareByDefaultSettings(): array
];
}

/**
* @dataProvider shareByDefaultSettings
*/
#[DataProvider('shareByDefaultSettings')]
public function testReturnsDiscreteInstancesIfOptionsAreProvidedRegardlessOfShareByDefaultSetting(
bool $shareByDefault
): void {
Expand Down Expand Up @@ -164,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,
Expand All @@ -175,8 +174,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
{
Expand All @@ -186,21 +183,17 @@ 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());

self::assertFalse($pluginManager->has(InvokableObject::class));
}

/**
* @group migration
* @group autoinvokable
*/
#[Group('migration')]
#[Group('autoinvokable')]
public function testSupportsRetrievingAutoInvokableServicesByDefault(): void
{
$pluginManager = new SimplePluginManager(new ServiceManager());
Expand All @@ -209,10 +202,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());
Expand All @@ -232,10 +223,8 @@ public function testPassingServiceInstanceViaConfigureShouldRaiseExceptionForInv
]);
}

/**
* @group 79
* @group 78
*/
#[Group('79')]
#[Group('78')]
public function testAbstractFactoryGetsCreationContext(): void
{
$serviceManager = new ServiceManager();
Expand Down
10 changes: 4 additions & 6 deletions test/Command/AheadOfTimeFactoryCreatorCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
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;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -21,9 +23,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 */
Expand Down Expand Up @@ -60,9 +60,7 @@ public static function invalidFactoryTargetPaths(): array
];
}

/**
* @dataProvider invalidFactoryTargetPaths
*/
#[DataProvider('invalidFactoryTargetPaths')]
public function testEmitsErrorMessageIfFactoryTargetPathDoesNotMatchRequirements(string $factoryTargetPath): void
{
$command = new AheadOfTimeFactoryCreatorCommand([], $factoryTargetPath, $this->factoryCompiler);
Expand Down
5 changes: 2 additions & 3 deletions test/Command/ConfigDumperCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,9 +21,7 @@
use function realpath;
use function sprintf;

/**
* @covers \Laminas\ServiceManager\Command\ConfigDumperCommand
*/
#[CoversClass(ConfigDumperCommand::class)]
final class ConfigDumperCommandTest extends TestCase
{
private vfsStreamDirectory $configDir;
Expand Down
10 changes: 4 additions & 6 deletions test/Command/FactoryCreatorCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -18,9 +20,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;
Expand Down Expand Up @@ -55,9 +55,7 @@ public static function invalidArguments(): array
];
}

/**
* @dataProvider invalidArguments
*/
#[DataProvider('invalidArguments')]
public function testEmitsErrorMessageIfArgumentIsNotAClass(string $argument): void
{
$this->input
Expand Down
Loading

0 comments on commit d41c0a6

Please sign in to comment.