From ce04c13ea8b6fc80f71e8d1740dc8a63d291a7f5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 27 Jul 2020 01:58:12 -0400 Subject: [PATCH] Update App\Router-related tests after constructor signature change --- tests/src/App/ModuleTest.php | 7 ++++++- tests/src/App/RouterTest.php | 36 ++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/tests/src/App/ModuleTest.php b/tests/src/App/ModuleTest.php index a7c439d1fd..03bb14b605 100644 --- a/tests/src/App/ModuleTest.php +++ b/tests/src/App/ModuleTest.php @@ -22,6 +22,7 @@ namespace Friendica\Test\src\App; use Friendica\App; +use Friendica\Core\Cache\ICache; use Friendica\Core\Config\IConfig; use Friendica\Core\L10n; use Friendica\LegacyModule; @@ -175,7 +176,11 @@ class ModuleTest extends DatabaseTest $l10n = \Mockery::mock(L10n::class); $l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; }); - $router = (new App\Router([], $l10n))->loadRoutes(include __DIR__ . '/../../../static/routes.config.php'); + $cache = \Mockery::mock(ICache::class); + $cache->shouldReceive('get')->with('routerDispatchData')->andReturn('')->atMost()->once(); + $cache->shouldReceive('set')->withAnyArgs()->andReturn(false)->atMost()->once(); + + $router = (new App\Router([], __DIR__ . '/../../../static/routes.config.php', $l10n, $cache)); $module = (new App\Module($name))->determineClass(new App\Arguments('', $command), $router, $config); diff --git a/tests/src/App/RouterTest.php b/tests/src/App/RouterTest.php index 064e37a12a..df1ea5e9ad 100644 --- a/tests/src/App/RouterTest.php +++ b/tests/src/App/RouterTest.php @@ -22,6 +22,7 @@ namespace Friendica\Test\src\App; use Friendica\App\Router; +use Friendica\Core\Cache\ICache; use Friendica\Core\L10n; use Friendica\Module; use Friendica\Network\HTTPException\MethodNotAllowedException; @@ -33,6 +34,10 @@ class RouterTest extends TestCase { /** @var L10n|MockInterface */ private $l10n; + /** + * @var ICache + */ + private $cache; protected function setUp() { @@ -40,11 +45,15 @@ class RouterTest extends TestCase $this->l10n = \Mockery::mock(L10n::class); $this->l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; }); + + $this->cache = \Mockery::mock(ICache::class); + $this->cache->shouldReceive('get')->andReturn(null); + $this->cache->shouldReceive('set')->andReturn(false); } public function testGetModuleClass() { - $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n); + $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache); $routeCollector = $router->getRouteCollector(); $routeCollector->addRoute([Router::GET], '/', 'IndexModuleClassName'); @@ -68,7 +77,7 @@ class RouterTest extends TestCase public function testPostModuleClass() { - $router = new Router(['REQUEST_METHOD' => Router::POST], $this->l10n); + $router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache); $routeCollector = $router->getRouteCollector(); $routeCollector->addRoute([Router::POST], '/', 'IndexModuleClassName'); @@ -94,7 +103,7 @@ class RouterTest extends TestCase { $this->expectException(NotFoundException::class); - $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n); + $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache); $router->getModuleClass('/unsupported'); } @@ -103,7 +112,7 @@ class RouterTest extends TestCase { $this->expectException(NotFoundException::class); - $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n); + $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache); $routeCollector = $router->getRouteCollector(); $routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName'); @@ -115,7 +124,7 @@ class RouterTest extends TestCase { $this->expectException(NotFoundException::class); - $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n); + $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache); $routeCollector = $router->getRouteCollector(); $routeCollector->addRoute([Router::GET], '/optional[/option]', 'OptionalModuleClassName'); @@ -127,7 +136,7 @@ class RouterTest extends TestCase { $this->expectException(NotFoundException::class); - $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n); + $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache); $routeCollector = $router->getRouteCollector(); $routeCollector->addRoute([Router::GET], '/variable/{var}', 'VariableModuleClassName'); @@ -139,7 +148,7 @@ class RouterTest extends TestCase { $this->expectException(MethodNotAllowedException::class); - $router = new Router(['REQUEST_METHOD' => Router::POST], $this->l10n); + $router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache); $routeCollector = $router->getRouteCollector(); $routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName'); @@ -151,7 +160,7 @@ class RouterTest extends TestCase { $this->expectException(MethodNotAllowedException::class); - $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n); + $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache); $routeCollector = $router->getRouteCollector(); $routeCollector->addRoute([Router::POST], '/test', 'TestModuleClassName'); @@ -189,9 +198,12 @@ class RouterTest extends TestCase */ public function testGetRoutes(array $routes) { - $router = (new Router([ - 'REQUEST_METHOD' => Router::GET - ], $this->l10n))->loadRoutes($routes); + $router = (new Router( + ['REQUEST_METHOD' => Router::GET], + '', + $this->l10n, + $this->cache + ))->loadRoutes($routes); $this->assertEquals(Module\Home::class, $router->getModuleClass('/')); $this->assertEquals(Module\Friendica::class, $router->getModuleClass('/group/route')); @@ -206,7 +218,7 @@ class RouterTest extends TestCase { $router = (new Router([ 'REQUEST_METHOD' => Router::POST - ], $this->l10n))->loadRoutes($routes); + ], '', $this->l10n, $this->cache))->loadRoutes($routes); // Don't find GET $this->assertEquals(Module\NodeInfo::class, $router->getModuleClass('/post/it'));