diff --git a/src/Middleware/RedirectToNewDomainMiddlewareFactory.php b/src/Middleware/RedirectToNewDomainMiddlewareFactory.php index 10847f3..9759437 100644 --- a/src/Middleware/RedirectToNewDomainMiddlewareFactory.php +++ b/src/Middleware/RedirectToNewDomainMiddlewareFactory.php @@ -5,6 +5,7 @@ namespace Settermjd\Middleware; use Psr\Container\ContainerInterface; +use Psr\Log\LoggerInterface; use Settermjd\Middleware\Exception\InvalidConfigurationException; /** @@ -37,6 +38,7 @@ public function __invoke(ContainerInterface $container): RedirectToNewDomainMidd oldDomain: $oldDomain, newDomain: $newDomain, redirectStatus: $redirectStatus, + logger: $container->get(LoggerInterface::class) ?? null ); } } diff --git a/test/Middleware/RedirectToNewDomainMiddlewareFactoryTest.php b/test/Middleware/RedirectToNewDomainMiddlewareFactoryTest.php index d04795b..6fef891 100644 --- a/test/Middleware/RedirectToNewDomainMiddlewareFactoryTest.php +++ b/test/Middleware/RedirectToNewDomainMiddlewareFactoryTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use Psr\Log\LoggerInterface; use Settermjd\Middleware\Exception\InvalidConfigurationException; use Settermjd\Middleware\RedirectToNewDomainMiddleware; use Settermjd\Middleware\RedirectToNewDomainMiddlewareFactory; @@ -23,16 +24,18 @@ public function testCanInstantiateMiddlewareWithConfigDataWhenSet(): void ->with("config") ->willReturn(true); $container - ->expects($this->once()) + ->expects($this->atMost(2)) ->method("get") - ->with("config") - ->willReturn([ - "redirect-to-new-domain-middleware" => [ - "old" => "deploywithdockercompose.com", - "new" => "https://deploywithdockercompose.webdevwithmatt.com", - "status" => 301, + ->willReturnOnConsecutiveCalls( + [ + "redirect-to-new-domain-middleware" => [ + "old" => "deploywithdockercompose.com", + "new" => "https://deploywithdockercompose.webdevwithmatt.com", + "status" => 301, + ], ], - ]); + $this->createMock(LoggerInterface::class), + ); $middleware = $factory($container); self::assertInstanceOf(RedirectToNewDomainMiddleware::class, $middleware);