mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 01:03:13 +08:00
Update to PHPUnit 10
This commit is contained in:
@@ -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;
|
||||
},
|
||||
);
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user