Skip to content

Commit

Permalink
refactor: add closure void return type in tests (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored Dec 29, 2024
1 parent 8b0beb3 commit b8f44e4
Show file tree
Hide file tree
Showing 25 changed files with 103 additions and 102 deletions.
3 changes: 2 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,5 @@
->withComposerBased(phpunit: true)
->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [
ClassPropertyAssignToConstructorPromotionRector::RENAME_PROPERTY => false,
]);
])
->withTypeCoverageLevel(0);
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testProcessMiddlewareWithTokenStorageProvider(): void
$request
->expects($this->exactly(2))
->method('withAttribute')
->willReturnCallback(function (string $key, string $value) use ($matcher, $tokenStorage) {
->willReturnCallback(function (string $key, string $value) use ($matcher, $tokenStorage): void {
match ($matcher->numberOfInvocations()) {
1 => $this->assertInstanceOf(AuthContextInterface::class, $value),
2 => $this->assertSame($tokenStorage, $value),
Expand Down
4 changes: 2 additions & 2 deletions src/Boot/tests/BootloadManager/BootloadManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function testWithoutInvokerStrategy(): void
SampleBootWithMethodBoot::class,
SampleBoot::class,
], [
static function(Container $container, SampleBoot $boot) {
static function(Container $container, SampleBoot $boot): void {
$container->bind('efg', $boot);
}
], [
static function(Container $container, SampleBoot $boot) {
static function(Container $container, SampleBoot $boot): void {
$container->bind('ghi', $boot);
}
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Boot/tests/BootloadManager/BootloadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public function testSchemaLoading(): void
SampleBootWithMethodBoot::class,
SampleBoot::class,
], [
static function(Container $container, SampleBoot $boot) {
static function(Container $container, SampleBoot $boot): void {
$container->bind('efg', $boot);
}
], [
static function(Container $container, SampleBoot $boot) {
static function(Container $container, SampleBoot $boot): void {
$container->bind('ghi', $boot);
}
]);
Expand Down
8 changes: 4 additions & 4 deletions src/Boot/tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ public function testBootingCallbacks()
{
$kernel = TestCore::create(['root' => __DIR__]);

$kernel->booting(static function (TestCore $core) {
$kernel->booting(static function (TestCore $core): void {
$core->getContainer()->bind('abc', 'foo');
});

$kernel->booting(static function (TestCore $core) {
$kernel->booting(static function (TestCore $core): void {
$core->getContainer()->bind('bcd', 'foo');
});

$kernel->booted( static function (TestCore $core) {
$kernel->booted( static function (TestCore $core): void {
$core->getContainer()->bind('cde', 'foo');
});

$kernel->booted( static function (TestCore $core) {
$kernel->booted( static function (TestCore $core): void {
$core->getContainer()->bind('def', 'foo');
});

Expand Down
6 changes: 3 additions & 3 deletions src/Core/tests/Scope/ExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testParentScopeResolvingCustomException(): void

$container = new Container();

$container->runScoped(static function (Container $c1) {
$container->runScoped(static function (Container $c1): void {
try {
$c1->get(ExceptionConstructor::class);
self::fail('Exception should be thrown');
Expand All @@ -38,7 +38,7 @@ public function testParentScopeThrowConstructorErrorOnResolving(): void

$container = new Container();

$container->runScoped(static function (Container $c1) {
$container->runScoped(static function (Container $c1): void {
try {
$c1->get(ExceptionConstructor::class);
self::fail('Exception should be thrown');
Expand All @@ -56,7 +56,7 @@ public function testParentScopeResolvingNotFound(): void

$container = new Container();

$container->runScoped(static function (Container $c1) {
$container->runScoped(static function (Container $c1): void {
try {
$c1->get(DatetimeCarrier::class);
self::fail('Exception should be thrown');
Expand Down
2 changes: 1 addition & 1 deletion src/Core/tests/Scope/FibersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testSingleFiberNestedContainers(): void

FiberHelper::runInFiber(
self::functionScopedTestDataIterator(),
static function (mixed $suspendValue) {
static function (mixed $suspendValue): void {
self::assertNull(ContainerScope::getContainer());
self::assertTrue(\in_array($suspendValue, self::TEST_DATA, true));
},
Expand Down
4 changes: 2 additions & 2 deletions src/Core/tests/Scope/FinalizeAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function testExceptionOnDestroy()
self::expectExceptionMessage('An exception has been thrown during finalization of the scope `foo`');

try {
$root->runScoped(static function (Container $c1) {
$root->runScoped(static function (Container $c1): void {
$obj = $c1->get(AttrScopeFooFinalize::class);
$obj->throwException = true;
}, name: 'foo');
Expand Down Expand Up @@ -154,7 +154,7 @@ public function testManyExceptionsOnDestroy()
self::expectExceptionMessage('3 exceptions have been thrown during finalization of the scope `foo`');

try {
$root->runScoped(static function (Container $c1) {
$root->runScoped(static function (Container $c1): void {
$c1->get(AttrScopeFooFinalize::class)->throwException = true;
$c1->get(AttrScopeFooFinalize::class)->throwException = true;
$c1->get(AttrScopeFooFinalize::class)->throwException = true;
Expand Down
30 changes: 15 additions & 15 deletions src/Core/tests/Scope/ProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testDifferentBindingsParallelScopes(): void
LoggerInterface::class => KVLogger::class,
],
),
static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc) {
static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc): void {
// from the current `foo` scope
self::assertInstanceOf(KVLogger::class, $logger);

Expand All @@ -65,7 +65,7 @@ static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use
LoggerInterface::class => FileLogger::class,
],
),
static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc) {
static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc): void {
// from the current `foo` scope
self::assertInstanceOf(FileLogger::class, $logger);

Expand All @@ -86,14 +86,14 @@ public function testResolveSameDependencyFromDifferentScopesSingleton(): void
$root = new Container();
$root->getBinder('http')->bindSingleton(LoggerInterface::class, KVLogger::class);

$root->runScope(new Scope(), static function (Container $c1) {
$root->runScope(new Scope(), static function (Container $c1): void {
$c1->runScope(
new Scope(name: 'http'),
static function (
ScopedProxyLoggerCarrier $carrier,
ScopedProxyLoggerCarrier $carrier2,
LoggerInterface $logger,
) {
): void {
// from the current `foo` scope
self::assertInstanceOf(KVLogger::class, $logger);

Expand All @@ -113,10 +113,10 @@ public function testResolveSameDependencyFromDifferentScopesNotSingleton(): void
$root = new Container();
$root->getBinder('foo')->bind(LoggerInterface::class, KVLogger::class);

$root->runScope(new Scope(), static function (Container $c1) {
$root->runScope(new Scope(), static function (Container $c1): void {
$c1->runScope(
new Scope(name: 'foo'),
static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) {
static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger): void {
// from the current `foo` scope
self::assertInstanceOf(KVLogger::class, $logger);

Expand Down Expand Up @@ -146,8 +146,8 @@ public function createInjection(\ReflectionClass $class, mixed $context = null):
),
);

$root->runScope(new Scope(), static function (Container $c1) {
$c1->runScope(new Scope(name: 'foo'), static function (Container $c, ContextInterface $param) {
$root->runScope(new Scope(), static function (Container $c1): void {
$c1->runScope(new Scope(name: 'foo'), static function (Container $c, ContextInterface $param): void {
self::assertInstanceOf(ReflectionParameter::class, $param->value);
self::assertSame('param', $param->value->getName());

Expand Down Expand Up @@ -188,14 +188,14 @@ public function createInjection(\ReflectionClass $class, mixed $context = null):
);

FiberHelper::runFiberSequence(
static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx) {
static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx): void {
for ($i = 0; $i < 10; $i++) {
self::assertInstanceOf(ReflectionParameter::class, $ctx->getValue(), 'Context injected');
self::assertSame('ctx', $ctx->getValue()->getName());
\Fiber::suspend();
}
}),
static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context) {
static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context): void {
for ($i = 0; $i < 10; $i++) {
self::assertInstanceOf(ReflectionParameter::class, $context->getValue(), 'Context injected');
self::assertSame('context', $context->getValue()->getName());
Expand All @@ -212,8 +212,8 @@ public function testCurrentScopeContainer(): void

$root->runScope(
new Scope(),
static function (#[Proxy] ContainerInterface $cp) use ($root) {
$root->runScope(new Scope(name: 'http'), static function (ContainerInterface $c) use ($cp) {
static function (#[Proxy] ContainerInterface $cp) use ($root): void {
$root->runScope(new Scope(name: 'http'), static function (ContainerInterface $c) use ($cp): void {
self::assertNotSame($c, $cp);
self::assertSame($c, $cp->get(ContainerInterface::class));
self::assertInstanceOf(KVLogger::class, $cp->get(LoggerInterface::class));
Expand Down Expand Up @@ -286,7 +286,7 @@ public function testImplementationWithWiderTypes(): void

$root->runScope(
new Scope('http'),
static function () use ($root, $proxy) {
static function () use ($root, $proxy): void {
self::assertSame('Foo', $proxy->getName());
$proxy->setName(new class implements \Stringable {
public function __toString(): string
Expand Down Expand Up @@ -353,9 +353,9 @@ public function testProxyIntoContainerScope(): void

$root->runScope(
new Scope(),
static function (#[Proxy] ContainerInterface $proxy, ContainerInterface $scoped) {
static function (#[Proxy] ContainerInterface $proxy, ContainerInterface $scoped): void {
self::assertNotSame($scoped, $proxy);
ContainerScope::runScope($proxy, static function (ContainerInterface $passed) use ($proxy, $scoped) {
ContainerScope::runScope($proxy, static function (ContainerInterface $passed) use ($proxy, $scoped): void {
self::assertNotSame($passed, $proxy);
self::assertSame($scoped, ContainerScope::getContainer());
});
Expand Down
42 changes: 21 additions & 21 deletions src/Core/tests/Scope/ScopeAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function testNamedScopeResolveFromRootInNullScope(): void
{
$root = self::makeContainer();

$root->runScoped(static function (Container $c1) {
$c1->runScoped(static function (Container $c2) use ($c1) {
$root->runScoped(static function (Container $c1): void {
$c1->runScoped(static function (Container $c2) use ($c1): void {
$obj1 = $c1->get(AttrScopeFooSingleton::class);
$obj2 = $c2->get(AttrScopeFooSingleton::class);

Expand All @@ -54,8 +54,8 @@ public function testNamedScopeResolveFromParentScope(): void
$root = self::makeContainer();
$root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo());

$root->runScoped(static function (Container $fooScope) {
$fooScope->runScoped(static function (Container $container) {
$root->runScoped(static function (Container $fooScope): void {
$fooScope->runScoped(static function (Container $container): void {
self::assertInstanceOf(AttrScopeFoo::class, $container->get('binding'));
}, name: 'bar');
}, name: 'foo');
Expand All @@ -69,8 +69,8 @@ public function testBadScopeExceptionAllParentNamedScopesNotContainsNeededScope(
$root = self::makeContainer();
$root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo());

$root->runScoped(static function (Container $fooScope) {
$fooScope->runScoped(static function (Container $container) {
$root->runScoped(static function (Container $fooScope): void {
$fooScope->runScoped(static function (Container $container): void {
$container->get('binding');
}, name: 'bar');
}, name: 'baz');
Expand All @@ -81,8 +81,8 @@ public function testAllParentNamedScopesNotContainsNeededScopeWithDisabledChecki
$root = self::makeContainer(checkScope: false);
$root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo());

$root->runScoped(static function (Container $fooScope) {
$fooScope->runScoped(static function (Container $container) {
$root->runScoped(static function (Container $fooScope): void {
$fooScope->runScoped(static function (Container $container): void {
self::assertInstanceOf(AttrScopeFoo::class, $container->get('binding'));
}, name: 'bar');
}, name: 'baz');
Expand All @@ -101,8 +101,8 @@ public function testRequestObjectFromValidScopeUsingFactoryFromWrongScope(): voi
$root = self::makeContainer();
$root->bind('foo', self::makeFooScopeObject(...));

$root->runScoped(static function (Container $c1) {
$c1->runScoped(static function (Container $c2) {
$root->runScoped(static function (Container $c1): void {
$c1->runScoped(static function (Container $c2): void {
$c2->get('foo');
}, name: 'foo');
});
Expand All @@ -114,8 +114,8 @@ public function testRequestObjectFromValidScopeUsingFactoryFromWrongScopeWithDis
$root = self::makeContainer(checkScope: false);
$root->bind('foo', self::makeFooScopeObject(...));

$root->runScoped(static function (Container $c1) {
$c1->runScoped(static function (Container $c2) {
$root->runScoped(static function (Container $c1): void {
$c1->runScoped(static function (Container $c2): void {
self::assertInstanceOf(AttrScopeFoo::class, $c2->get('foo'));
}, name: 'foo');
});
Expand All @@ -133,8 +133,8 @@ public function testNamedScopeUseFactoryInWrongParentScope(): void
$root = self::makeContainer();
$root->bind('foo', self::makeFooScopeObject(...));

$root->runScoped(static function (Container $c1) {
$c1->runScoped(static function (Container $c2) {
$root->runScoped(static function (Container $c1): void {
$c1->runScoped(static function (Container $c2): void {
$c2->get('foo');
});
});
Expand All @@ -146,8 +146,8 @@ public function testNamedScopeUseFactoryInWrongParentScopeWithDisabledChecking()
$root = self::makeContainer(checkScope: false);
$root->bind('foo', self::makeFooScopeObject(...));

$root->runScoped(static function (Container $c1) {
$c1->runScoped(static function (Container $c2) {
$root->runScoped(static function (Container $c1): void {
$c1->runScoped(static function (Container $c2): void {
self::assertInstanceOf(AttrScopeFoo::class, $c2->get('foo'));
});
});
Expand All @@ -166,9 +166,9 @@ public function testNamedScopeDuplication(): void
$root = self::makeContainer();

try {
$root->runScoped(static function (Container $c1) {
$c1->runScoped(static function (Container $c2) {
$c2->runScoped(static function (Container $c3) {
$root->runScoped(static function (Container $c1): void {
$c1->runScoped(static function (Container $c2): void {
$c2->runScoped(static function (Container $c3): void {
// do nothing
}, name: 'root');
});
Expand All @@ -190,8 +190,8 @@ public function testBadScopeException(): void

try {
$root = self::makeContainer();
$root->runScoped(static function (Container $c1) {
$c1->runScoped(static function (Container $c2) {
$root->runScoped(static function (Container $c1): void {
$c1->runScoped(static function (Container $c2): void {
$c2->get(AttrScopeFoo::class);
});
}, name: 'bar');
Expand Down
6 changes: 3 additions & 3 deletions src/Core/tests/Scope/SideEffectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public function testResolveSameDependencyFromDifferentScopes(): void
$root = new Container();
$root->bind(LoggerInterface::class, KVLogger::class);

$root->runScope(new Scope(), static function (Container $c1) {
$root->runScope(new Scope(), static function (Container $c1): void {
$c1->bind(LoggerInterface::class, FileLogger::class);

$c1->runScope(new Scope(), static function (LoggerCarrier $carrier, LoggerInterface $logger) {
$c1->runScope(new Scope(), static function (LoggerCarrier $carrier, LoggerInterface $logger): void {
// from the $root container
self::assertInstanceOf(KVLogger::class, $carrier->logger);
// from the $c1 container
Expand All @@ -42,7 +42,7 @@ public function testFactory(): void
$root = new Container();
$root->bind(LoggerInterface::class, KVLogger::class);

$root->runScope(new Scope(), static function (Container $c1) {
$root->runScope(new Scope(), static function (Container $c1): void {
$c1->bind(LoggerInterface::class, FileLogger::class);

self::assertInstanceOf(
Expand Down
Loading

0 comments on commit b8f44e4

Please sign in to comment.