diff --git a/src/UrlHelperMiddleware.php b/src/UrlHelperMiddleware.php index 9a1ac4c..5b9f4bb 100644 --- a/src/UrlHelperMiddleware.php +++ b/src/UrlHelperMiddleware.php @@ -4,7 +4,6 @@ namespace Mezzio\Helper; -use Mezzio\Helper\UrlHelper; use Mezzio\Router\RouteResult; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -16,7 +15,7 @@ */ class UrlHelperMiddleware implements MiddlewareInterface { - public function __construct(private UrlHelper $helper) + public function __construct(private UrlHelperInterface $helper) { } diff --git a/src/UrlHelperMiddlewareFactory.php b/src/UrlHelperMiddlewareFactory.php index a4505b4..7b64f5c 100644 --- a/src/UrlHelperMiddlewareFactory.php +++ b/src/UrlHelperMiddlewareFactory.php @@ -46,7 +46,7 @@ public function __invoke(ContainerInterface $container): UrlHelperMiddleware } $helper = $container->get($this->urlHelperServiceName); - assert($helper instanceof UrlHelper); + assert($helper instanceof UrlHelperInterface); return new UrlHelperMiddleware($helper); } diff --git a/test/UrlHelperMiddlewareFactoryTest.php b/test/UrlHelperMiddlewareFactoryTest.php index 3fe09c9..14eb000 100644 --- a/test/UrlHelperMiddlewareFactoryTest.php +++ b/test/UrlHelperMiddlewareFactoryTest.php @@ -6,6 +6,7 @@ use Mezzio\Helper\Exception\MissingHelperException; use Mezzio\Helper\UrlHelper; +use Mezzio\Helper\UrlHelperInterface; use Mezzio\Helper\UrlHelperMiddleware; use Mezzio\Helper\UrlHelperMiddlewareFactory; use PHPUnit\Framework\MockObject\MockObject; @@ -90,4 +91,16 @@ public function testFactoryAllowsSerialization(): void self::assertInstanceOf(UrlHelperMiddlewareFactory::class, $factory); self::assertAttributeSame('MyUrlHelper', 'urlHelperServiceName', $factory); } + + public function testFactoryAllowsCustomUrlHelperInterfaceImplementations(): void + { + $helper = $this->createMock(UrlHelperInterface::class); + $this->injectContainer('MyUrlHelper', $helper); + $factory = new UrlHelperMiddlewareFactory('MyUrlHelper'); + + $middleware = $factory($this->container); + + self::assertInstanceOf(UrlHelperMiddleware::class, $middleware); + self::assertAttributeSame($helper, 'helper', $middleware); + } } diff --git a/test/UrlHelperMiddlewareTest.php b/test/UrlHelperMiddlewareTest.php index bf497aa..f63a3d2 100644 --- a/test/UrlHelperMiddlewareTest.php +++ b/test/UrlHelperMiddlewareTest.php @@ -4,7 +4,7 @@ namespace MezzioTest\Helper; -use Mezzio\Helper\UrlHelper; +use Mezzio\Helper\UrlHelperInterface; use Mezzio\Helper\UrlHelperMiddleware; use Mezzio\Router\RouteResult; use PHPUnit\Framework\MockObject\MockObject; @@ -16,8 +16,8 @@ /** @covers \Mezzio\Helper\UrlHelperMiddleware */ final class UrlHelperMiddlewareTest extends TestCase { - /** @var UrlHelper&MockObject */ - private UrlHelper $helper; + /** @var UrlHelperInterface&MockObject */ + private UrlHelperInterface $helper; private UrlHelperMiddleware $middleware; @@ -25,7 +25,7 @@ protected function setUp(): void { parent::setUp(); - $this->helper = $this->createMock(UrlHelper::class); + $this->helper = $this->createMock(UrlHelperInterface::class); $this->middleware = new UrlHelperMiddleware($this->helper); }