From b911da3e1eedff9f7df683889f0d425d47a6fd1c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Feb 2023 14:47:50 +0100 Subject: DI for Router Signed-off-by: Robin Appelman --- tests/lib/AppFramework/Routing/RoutingTest.php | 52 +++++++++++++++++++++++--- tests/lib/Route/RouterTest.php | 12 +++++- 2 files changed, 57 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/lib/AppFramework/Routing/RoutingTest.php b/tests/lib/AppFramework/Routing/RoutingTest.php index 22037c31d0d..d7fde02dbcb 100644 --- a/tests/lib/AppFramework/Routing/RoutingTest.php +++ b/tests/lib/AppFramework/Routing/RoutingTest.php @@ -6,8 +6,12 @@ use OC\AppFramework\DependencyInjection\DIContainer; use OC\AppFramework\Routing\RouteConfig; use OC\Route\Route; use OC\Route\Router; +use OCP\Diagnostics\IEventLogger; +use OCP\IConfig; +use OCP\IRequest; use OCP\Route\IRouter; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; class RoutingTest extends \Test\TestCase { @@ -133,7 +137,13 @@ class RoutingTest extends \Test\TestCase { /** @var IRouter|MockObject $router */ $router = $this->getMockBuilder(Router::class) ->onlyMethods(['create']) - ->setConstructorArgs([$this->createMock(LoggerInterface::class)]) + ->setConstructorArgs([ + $this->createMock(LoggerInterface::class), + $this->createMock(IRequest::class), + $this->createMock(IConfig::class), + $this->createMock(IEventLogger::class), + $this->createMock(ContainerInterface::class) + ]) ->getMock(); // load route configuration @@ -154,7 +164,13 @@ class RoutingTest extends \Test\TestCase { /** @var IRouter|MockObject $router */ $router = $this->getMockBuilder(Router::class) ->onlyMethods(['create']) - ->setConstructorArgs([$this->createMock(LoggerInterface::class)]) + ->setConstructorArgs([ + $this->createMock(LoggerInterface::class), + $this->createMock(IRequest::class), + $this->createMock(IConfig::class), + $this->createMock(IEventLogger::class), + $this->createMock(ContainerInterface::class) + ]) ->getMock(); // load route configuration @@ -214,7 +230,13 @@ class RoutingTest extends \Test\TestCase { /** @var IRouter|MockObject $router */ $router = $this->getMockBuilder(Router::class) ->onlyMethods(['create']) - ->setConstructorArgs([$this->createMock(LoggerInterface::class)]) + ->setConstructorArgs([ + $this->createMock(LoggerInterface::class), + $this->createMock(IRequest::class), + $this->createMock(IConfig::class), + $this->createMock(IEventLogger::class), + $this->createMock(ContainerInterface::class) + ]) ->getMock(); // we expect create to be called once: @@ -264,7 +286,13 @@ class RoutingTest extends \Test\TestCase { /** @var IRouter|MockObject $router */ $router = $this->getMockBuilder(Router::class) ->onlyMethods(['create']) - ->setConstructorArgs([$this->createMock(LoggerInterface::class)]) + ->setConstructorArgs([ + $this->createMock(LoggerInterface::class), + $this->createMock(IRequest::class), + $this->createMock(IConfig::class), + $this->createMock(IEventLogger::class), + $this->createMock(ContainerInterface::class) + ]) ->getMock(); // we expect create to be called once: @@ -291,7 +319,13 @@ class RoutingTest extends \Test\TestCase { /** @var IRouter|MockObject $router */ $router = $this->getMockBuilder(Router::class) ->onlyMethods(['create']) - ->setConstructorArgs([$this->createMock(LoggerInterface::class)]) + ->setConstructorArgs([ + $this->createMock(LoggerInterface::class), + $this->createMock(IRequest::class), + $this->createMock(IConfig::class), + $this->createMock(IEventLogger::class), + $this->createMock(ContainerInterface::class) + ]) ->getMock(); // route mocks @@ -338,7 +372,13 @@ class RoutingTest extends \Test\TestCase { /** @var IRouter|MockObject $router */ $router = $this->getMockBuilder(Router::class) ->onlyMethods(['create']) - ->setConstructorArgs([$this->createMock(LoggerInterface::class)]) + ->setConstructorArgs([ + $this->createMock(LoggerInterface::class), + $this->createMock(IRequest::class), + $this->createMock(IConfig::class), + $this->createMock(IEventLogger::class), + $this->createMock(ContainerInterface::class) + ]) ->getMock(); // route mocks diff --git a/tests/lib/Route/RouterTest.php b/tests/lib/Route/RouterTest.php index 44fef6f1d4f..301058f74a6 100644 --- a/tests/lib/Route/RouterTest.php +++ b/tests/lib/Route/RouterTest.php @@ -24,6 +24,10 @@ declare(strict_types=1); namespace Test\Route; use OC\Route\Router; +use OCP\Diagnostics\IEventLogger; +use OCP\IConfig; +use OCP\IRequest; +use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -44,7 +48,13 @@ class RouterTest extends TestCase { $this->fail('Unexpected info log: '.(string)($data['exception'] ?? $message)); } ); - $router = new Router($logger); + $router = new Router( + $logger, + $this->createMock(IRequest::class), + $this->createMock(IConfig::class), + $this->createMock(IEventLogger::class), + $this->createMock(ContainerInterface::class), + ); $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index')); -- cgit v1.2.3