Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use PHPUnit 10 syntax #248

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +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">
<MixedInferredReturnType>
<code><![CDATA[array]]></code>
</MixedInferredReturnType>
<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 @@ -153,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 @@ -190,14 +220,13 @@
</UnusedVariable>
</file>
<file src="test/ServiceManagerTest.php">
<MixedInferredReturnType>
<code><![CDATA[array]]></code>
</MixedInferredReturnType>
<MixedOperand>
<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 @@ -230,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
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 @@ -103,9 +104,7 @@ public static function shareByDefaultSettings(): array
];
}

/**
* @dataProvider shareByDefaultSettings
*/
#[DataProvider('shareByDefaultSettings')]
public function testReturnsDiscreteInstancesIfOptionsAreProvidedRegardlessOfShareByDefaultSetting(
bool $shareByDefault
): void {
Expand Down Expand Up @@ -163,7 +162,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 @@ -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
{
Expand All @@ -185,21 +182,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 @@ -208,10 +201,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 @@ -231,10 +222,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