Skip to content

Commit

Permalink
Update to PHPUnit 10
Browse files Browse the repository at this point in the history
Signed-off-by: Filippo Tessarotto <[email protected]>
  • Loading branch information
Slamdunk committed Mar 21, 2023
1 parent 4be4b5b commit 2a49a11
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 424 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/.phpcs-cache
/phpcs.xml
/.phpbench
/.phpunit.cache/
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"laminas/laminas-dependency-plugin": "^2.2",
"mikey179/vfsstream": "^1.6.11",
"phpbench/phpbench": "^1.2.9",
"phpunit/phpunit": "^9.6.5",
"phpunit/phpunit": "^10.0.17",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.8.0"
},
Expand Down
579 changes: 226 additions & 353 deletions composer.lock

Large diffs are not rendered by default.

42 changes: 18 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>

<testsuites>
<testsuite name="laminas-servicemanager Test Suite">
<directory>./test/</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>disable</group>
</exclude>
</groups>

<php>
<ini name="date.timezone" value="UTC"/>
</php>
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
cacheDirectory=".phpunit.cache">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="laminas-servicemanager Test Suite">
<directory>./test/</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>disable</group>
</exclude>
</groups>
</phpunit>
8 changes: 2 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,6 @@
<MissingClosureReturnType>
<code>static function ($container, $name, $callback) {</code>
</MissingClosureReturnType>
<MissingConstructor>
<code>$creationContext</code>
<code>$creationContext</code>
</MissingConstructor>
<MixedArrayAssignment>
<code><![CDATA[$object[$shared ? $method : 'build'][]]]></code>
</MixedArrayAssignment>
Expand Down Expand Up @@ -524,8 +520,8 @@
</file>
<file src="test/Exception/CyclicAliasExceptionTest.php">
<InvalidDocblock>
<code>public function aliasesProvider(): array</code>
<code>public function cyclicAliasProvider(): array</code>
<code>public static function aliasesProvider(): array</code>
<code>public static function cyclicAliasProvider(): array</code>
</InvalidDocblock>
<MixedInferredReturnType>
<code><![CDATA[array<
Expand Down
9 changes: 5 additions & 4 deletions src/Test/CommonPluginManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laminas\ServiceManager\Exception\InvalidServiceException;
use ReflectionClass;
use ReflectionProperty;
use stdClass;

use function method_exists;

Expand Down Expand Up @@ -58,7 +59,7 @@ public function testRegisteringInvalidElementRaisesException()
public function testLoadingInvalidElementRaisesException()
{
$manager = $this->getPluginManager();
$manager->setInvokableClass('test', static::class);
$manager->setInvokableClass('test', stdClass::class);
$this->expectException($this->getServiceNotFoundException());
$manager->get('test');
}
Expand All @@ -76,9 +77,9 @@ public function testPluginAliasesResolve($alias, $expected)
/**
* @return array
*/
public function aliasProvider()
public static function aliasProvider(): array
{
$manager = $this->getPluginManager();
$manager = self::getPluginManager();
$reflection = new ReflectionProperty($manager, 'aliases');
$data = [];
foreach ($reflection->getValue($manager) as $alias => $expected) {
Expand All @@ -101,7 +102,7 @@ protected function getServiceNotFoundException(): string
*
* @return AbstractPluginManager
*/
abstract protected function getPluginManager();
abstract protected static function getPluginManager();

/**
* Returns the FQCN of the exception thrown under v2 by `validatePlugin()`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function setUp(): void
$this->factory = new ReflectionBasedAbstractFactory();
}

public function nonClassRequestedNames(): array
public static function nonClassRequestedNames(): array
{
return [
'non-class-string' => ['non-class-string'],
Expand Down
10 changes: 5 additions & 5 deletions test/AbstractPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ final class AbstractPluginManagerTest extends TestCase
{
use CommonServiceLocatorBehaviorsTrait;

public function createContainer(array $config = []): ServiceManager
public static function createContainer(array $config = []): ServiceManager
{
$this->creationContext = new ServiceManager();
return new TestAsset\LenientPluginManager($this->creationContext, $config);
self::$creationContext = new ServiceManager();
return new TestAsset\LenientPluginManager(self::$creationContext, $config);
}

public function testInjectCreationContextInFactories(): void
Expand Down Expand Up @@ -101,7 +101,7 @@ public function testCachesInstanceByDefaultIfNoOptionsArePassed(): void
self::assertSame($first, $second);
}

public function shareByDefaultSettings(): array
public static function shareByDefaultSettings(): array
{
return [
'true' => [true],
Expand Down Expand Up @@ -248,7 +248,7 @@ public function testCanPassConfigInterfaceAsFirstConstructorArgumentWithDeprecat
self::assertSame($pluginManager, $pluginManager->getCreationContext());
}

public function invalidConstructorArguments(): array
public static function invalidConstructorArguments(): array
{
return [
'true' => [true],
Expand Down
40 changes: 21 additions & 19 deletions test/CommonServiceLocatorBehaviorsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ trait CommonServiceLocatorBehaviorsTrait
/**
* The creation context container; used in some mocks for comparisons; set during createContainer.
*/
protected ServiceManager|null $creationContext;
protected static ServiceManager|null $creationContext;

/**
* @psalm-param ServiceManagerConfigurationType $config
* @return ServiceManager
* @todo This will need to be static for future versions of PHPUnit
*/
abstract public function createContainer(array $config = []);
abstract public static function createContainer(array $config = []);

public function testIsSharedByDefault(): void
{
Expand Down Expand Up @@ -271,7 +271,7 @@ public function testInitializersAreRunAfterCreation(): void
$initializer
->expects(self::once())
->method('__invoke')
->with($this->creationContext, self::isInstanceOf(stdClass::class));
->with(self::$creationContext, self::isInstanceOf(stdClass::class));

// We call it twice to make sure that the initializer is only called once

Expand Down Expand Up @@ -551,7 +551,7 @@ public function testCanSpecifyAbstractFactoryUsingStringViaConfiguration(): void
self::assertInstanceOf(DateTime::class, $dateTime);
}

public function invalidFactories(): array
public static function invalidFactories(): array
{
return [
'null' => [null],
Expand All @@ -566,9 +566,9 @@ public function invalidFactories(): array
];
}

public function invalidAbstractFactories(): array
public static function invalidAbstractFactories(): array
{
$factories = $this->invalidFactories();
$factories = self::invalidFactories();
$factories['non-class-string'] = ['non-callable-string', 'valid class name'];

return $factories;
Expand Down Expand Up @@ -610,9 +610,9 @@ public function testCanSpecifyInitializerUsingStringViaConfiguration(): void
self::assertEquals('bar', $instance->foo, '"foo" property was not properly injected');
}

public function invalidInitializers(): array
public static function invalidInitializers(): array
{
$factories = $this->invalidFactories();
$factories = self::invalidFactories();
$factories['non-class-string'] = ['non-callable-string', 'callable or an instance of'];

return $factories;
Expand Down Expand Up @@ -643,9 +643,9 @@ public function testGetRaisesExceptionWhenNoFactoryIsResolved(): void
$serviceManager->get('Some\Unknown\Service');
}

public function invalidDelegators(): array
public static function invalidDelegators(): array
{
$invalidDelegators = $this->invalidFactories();
$invalidDelegators = self::invalidFactories();
$invalidDelegators['invalid-classname'] = ['not-a-class-name', 'invalid delegator'];
$invalidDelegators['non-invokable-class'] = [stdClass::class];

Expand Down Expand Up @@ -852,12 +852,14 @@ public function testCanInjectSharingRules(): void
}

/** @return array<string, array{0: string, 1: mixed[]}> */
public function methodsAffectedByOverrideSettings(): array
public static function methodsAffectedByOverrideSettings(): array
{
// name => [ 'method to invoke', [arguments for invocation]]
$that = new stdClass();

return [
'setAlias' => ['setAlias', ['foo', 'bar']],
'setInvokableClass' => ['setInvokableClass', ['foo', self::class]],
'setInvokableClass' => ['setInvokableClass', ['foo', stdClass::class]],
'setFactory' => [
'setFactory',
[
Expand All @@ -866,9 +868,9 @@ static function (): void {
},
],
],
'setService' => ['setService', ['foo', $this]],
'setService' => ['setService', ['foo', $that]],
'setShared' => ['setShared', ['foo', false]],
'mapLazyService' => ['mapLazyService', ['foo', self::class]],
'mapLazyService' => ['mapLazyService', ['foo', stdClass::class]],
'addDelegator' => [
'addDelegator',
[
Expand All @@ -891,11 +893,11 @@ static function (): void {
],
],
],
'configure-service' => ['configure', [['services' => ['foo' => $this]]]],
'configure-service' => ['configure', [['services' => ['foo' => $that]]]],
'configure-shared' => ['configure', [['shared' => ['foo' => false]]]],
'configure-lazy-service' => [
'configure',
[['lazy_services' => ['class_map' => ['foo' => self::class]]]],
[['lazy_services' => ['class_map' => ['foo' => stdClass::class]]]],
],
];
}
Expand Down Expand Up @@ -946,7 +948,7 @@ public function testCanRetrieveParentContainerViaGetServiceLocatorWithDeprecatio

return true;
}, E_USER_DEPRECATED);
self::assertSame($this->creationContext, $container->getServiceLocator());
self::assertSame(self::$creationContext, $container->getServiceLocator());
restore_error_handler();
}

Expand Down Expand Up @@ -1047,7 +1049,7 @@ public function testConsistencyOverInternalStates(
*
* @return list<array{0: ServiceManager, 1: string, 2: list<string>, 3: bool}>
*/
public function provideConsistencyOverInternalStatesTests(): array
public static function provideConsistencyOverInternalStatesTests(): array
{
$config1 = [
'factories' => [
Expand Down Expand Up @@ -1103,7 +1105,7 @@ public function provideConsistencyOverInternalStatesTests(): array
$tests = [];

foreach ($configs as $config) {
$smTemplate = $this->createContainer($config);
$smTemplate = self::createContainer($config);

// setup sharing, services are always shared
$names = array_fill_keys(array_keys($config['services']), true);
Expand Down
2 changes: 1 addition & 1 deletion test/ExamplePluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class ExamplePluginManagerTest extends TestCase
{
use CommonPluginManagerTrait;

protected function getPluginManager(): V2v3PluginManager
protected static function getPluginManager(): V2v3PluginManager
{
return new V2v3PluginManager(new ServiceManager());
}
Expand Down
4 changes: 2 additions & 2 deletions test/Exception/CyclicAliasExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testFromCyclicAlias(string $alias, array $aliases, string $expec
* array{0:non-empty-string,1:array<non-empty-string,non-empty-string>,non-empty-string}
* >
*/
public function cyclicAliasProvider(): array
public static function cyclicAliasProvider(): array
{
return [
'a -> a' => [
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testFromAliasesMap(array $aliases, string $expectedMessage): voi
/**
* @return array<string, array{0: array<string, string>, string}>
*/
public function aliasesProvider(): array
public static function aliasesProvider(): array
{
return [
'empty set' => [
Expand Down
8 changes: 4 additions & 4 deletions test/ServiceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ final class ServiceManagerTest extends TestCase
/**
* @psalm-param ServiceManagerConfigurationType $config
*/
public function createContainer(array $config = []): ServiceManager
public static function createContainer(array $config = []): ServiceManager
{
$container = new ServiceManager($config);
$this->creationContext = $container;
self::$creationContext = $container;

return $container;
}
Expand Down Expand Up @@ -120,7 +120,7 @@ static function (ContainerInterface $container, string $name, callable $callback
self::assertEquals('bar', $instance->foo);
}

public function shareProvider(): array
public static function shareProvider(): array
{
$sharedByDefault = true;
$serviceShared = true;
Expand Down Expand Up @@ -546,7 +546,7 @@ public function testWontShareServiceWhenRequestedByAlias(array $config, string $
* 2:non-empty-string
* }>
*/
public function aliasedServices(): array
public static function aliasedServices(): array
{
return [
'invokables' => [
Expand Down
4 changes: 2 additions & 2 deletions test/Tool/ConfigDumperCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testEmitsHelpWhenNoArgumentsProvided(): void
self::assertEquals(0, $this->command->__invoke([]));
}

public function helpArguments(): array
public static function helpArguments(): array
{
return [
'short' => ['-h'],
Expand All @@ -82,7 +82,7 @@ public function helpArguments(): array
];
}

public function ignoreUnresolvedArguments(): array
public static function ignoreUnresolvedArguments(): array
{
return [
'short' => ['-i'],
Expand Down
4 changes: 2 additions & 2 deletions test/Tool/FactoryCreatorCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function assertHelp($stream = STDOUT): void
);
}

public function helpArguments(): array
public static function helpArguments(): array
{
return [
'short' => ['-h'],
Expand All @@ -75,7 +75,7 @@ public function testEmitsHelpWhenHelpArgumentProvidedAsFirstArgument(string $arg
self::assertSame(0, $this->command->__invoke([$argument]));
}

public function invalidArguments(): array
public static function invalidArguments(): array
{
return [
'string' => ['string'],
Expand Down

0 comments on commit 2a49a11

Please sign in to comment.