Update to PHPUnit 10

This commit is contained in:
Alejandro Celaya
2023-02-09 09:32:38 +01:00
parent ad44a8441a
commit 650a286982
131 changed files with 335 additions and 315 deletions

View File

@@ -6,6 +6,7 @@ namespace ShlinkioTest\Shlink\Core\ErrorHandler;
use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
@@ -58,40 +59,39 @@ class NotFoundRedirectHandlerTest extends TestCase
self::assertSame($expectedResp, $result);
}
public function provideNonRedirectScenarios(): iterable
public static function provideNonRedirectScenarios(): iterable
{
yield 'no domain' => [function (
MockObject&DomainServiceInterface $domainService,
MockObject&NotFoundRedirectResolverInterface $resolver,
): void {
$domainService->expects($this->once())->method('findByAuthority')->withAnyParameters()->willReturn(
$domainService->expects(self::once())->method('findByAuthority')->withAnyParameters()->willReturn(
null,
);
$resolver->expects($this->once())->method('resolveRedirectResponse')->with(
$this->isInstanceOf(NotFoundType::class),
$this->isInstanceOf(NotFoundRedirectOptions::class),
$this->isInstanceOf(UriInterface::class),
$resolver->expects(self::once())->method('resolveRedirectResponse')->with(
self::isInstanceOf(NotFoundType::class),
self::isInstanceOf(NotFoundRedirectOptions::class),
self::isInstanceOf(UriInterface::class),
)->willReturn(null);
}];
yield 'non-redirecting domain' => [function (
MockObject&DomainServiceInterface $domainService,
MockObject&NotFoundRedirectResolverInterface $resolver,
): void {
$domainService->expects($this->once())->method('findByAuthority')->withAnyParameters()->willReturn(
$domainService->expects(self::once())->method('findByAuthority')->withAnyParameters()->willReturn(
Domain::withAuthority(''),
);
$resolver->expects($this->exactly(2))->method('resolveRedirectResponse')->withConsecutive(
[
$this->isInstanceOf(NotFoundType::class),
$this->isInstanceOf(Domain::class),
$this->isInstanceOf(UriInterface::class),
],
[
$this->isInstanceOf(NotFoundType::class),
$this->isInstanceOf(NotFoundRedirectOptions::class),
$this->isInstanceOf(UriInterface::class),
],
)->willReturn(null);
$callCount = 0;
$resolver->expects(self::exactly(2))->method('resolveRedirectResponse')->willReturnCallback(
function (mixed $arg1, mixed $arg2, mixed $arg3) use (&$callCount) {
Assert::assertInstanceOf(NotFoundType::class, $arg1);
Assert::assertInstanceOf($callCount === 0 ? Domain::class : NotFoundRedirectOptions::class, $arg2);
Assert::assertInstanceOf(UriInterface::class, $arg3);
$callCount++;
return null;
},
);
}];
}

View File

@@ -11,11 +11,12 @@ use Mezzio\Router\Route;
use Mezzio\Router\RouteResult;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Shlinkio\Shlink\Core\Action\RedirectAction;
use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType;
use Shlinkio\Shlink\Core\ErrorHandler\NotFoundTemplateHandler;
use function Laminas\Stratigility\middleware;
class NotFoundTemplateHandlerTest extends TestCase
{
private NotFoundTemplateHandler $handler;
@@ -44,19 +45,20 @@ class NotFoundTemplateHandlerTest extends TestCase
self::assertTrue($this->readFileCalled);
}
public function provideTemplates(): iterable
public static function provideTemplates(): iterable
{
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/foo'));
yield 'base url' => [$this->withNotFoundType($request, '/foo'), NotFoundTemplateHandler::NOT_FOUND_TEMPLATE];
yield 'regular not found' => [$this->withNotFoundType($request), NotFoundTemplateHandler::NOT_FOUND_TEMPLATE];
yield 'base url' => [self::withNotFoundType($request, '/foo'), NotFoundTemplateHandler::NOT_FOUND_TEMPLATE];
yield 'regular not found' => [self::withNotFoundType($request), NotFoundTemplateHandler::NOT_FOUND_TEMPLATE];
yield 'invalid short code' => [
$this->withNotFoundType($request->withAttribute(
self::withNotFoundType($request->withAttribute(
RouteResult::class,
RouteResult::fromRoute(
new Route(
'foo',
$this->createMock(MiddlewareInterface::class),
middleware(function (): void {
}),
['GET'],
RedirectAction::class,
),
@@ -66,7 +68,7 @@ class NotFoundTemplateHandlerTest extends TestCase
];
}
private function withNotFoundType(ServerRequestInterface $req, string $baseUrl = ''): ServerRequestInterface
private static function withNotFoundType(ServerRequestInterface $req, string $baseUrl = ''): ServerRequestInterface
{
$type = NotFoundType::fromRequest($req, $baseUrl);
return $req->withAttribute(NotFoundType::class, $type);