]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/App/RouterTest.php
Replaced most "api_get_user" calls with newer BaseApi calls
[friendica.git] / tests / src / App / RouterTest.php
index a5824c45567983d129d4593709b11545d68c6156..f74ea423f04ce114605e6dee53482d683460b57c 100644 (file)
@@ -22,8 +22,9 @@
 namespace Friendica\Test\src\App;
 
 use Friendica\App\Router;
-use Friendica\Core\Cache\ICache;
+use Friendica\Core\Cache\Capability\ICanCache;
 use Friendica\Core\L10n;
+use Friendica\Core\Lock\Capability\ICanLock;
 use Friendica\Module;
 use Friendica\Network\HTTPException\MethodNotAllowedException;
 use Friendica\Network\HTTPException\NotFoundException;
@@ -36,9 +37,13 @@ class RouterTest extends TestCase
        /** @var L10n|MockInterface */
        private $l10n;
        /**
-        * @var ICache
+        * @var ICanCache
         */
        private $cache;
+       /**
+        * @var ICanLock
+        */
+       private $lock;
 
        protected function setUp() : void
        {
@@ -47,14 +52,18 @@ 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 = Mockery::mock(ICanCache::class);
                $this->cache->shouldReceive('get')->andReturn(null);
                $this->cache->shouldReceive('set')->andReturn(false);
+
+               $this->lock = Mockery::mock(ICanLock::class);
+               $this->lock->shouldReceive('acquire')->andReturn(true);
+               $this->lock->shouldReceive('isLocked')->andReturn(false);
        }
 
        public function testGetModuleClass()
        {
-               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache, $this->lock);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::GET], '/', 'IndexModuleClassName');
@@ -78,7 +87,7 @@ class RouterTest extends TestCase
 
        public function testPostModuleClass()
        {
-               $router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache);
+               $router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache, $this->lock);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::POST], '/', 'IndexModuleClassName');
@@ -104,7 +113,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(NotFoundException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache, $this->lock);
 
                $router->getModuleClass('/unsupported');
        }
@@ -113,7 +122,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(NotFoundException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache, $this->lock);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName');
@@ -125,7 +134,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(NotFoundException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache, $this->lock);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::GET], '/optional[/option]', 'OptionalModuleClassName');
@@ -137,7 +146,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(NotFoundException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache, $this->lock);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::GET], '/variable/{var}', 'VariableModuleClassName');
@@ -149,7 +158,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(MethodNotAllowedException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache);
+               $router = new Router(['REQUEST_METHOD' => Router::POST], '', $this->l10n, $this->cache, $this->lock);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName');
@@ -161,7 +170,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(MethodNotAllowedException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], '', $this->l10n, $this->cache, $this->lock);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::POST], '/test', 'TestModuleClassName');
@@ -203,7 +212,8 @@ class RouterTest extends TestCase
                        ['REQUEST_METHOD' => Router::GET],
                        '',
                        $this->l10n,
-                       $this->cache
+                       $this->cache,
+                       $this->lock
                ))->loadRoutes($routes);
 
                self::assertEquals(Module\Home::class, $router->getModuleClass('/'));
@@ -219,7 +229,7 @@ class RouterTest extends TestCase
        {
                $router = (new Router([
                        'REQUEST_METHOD' => Router::POST
-               ], '', $this->l10n, $this->cache))->loadRoutes($routes);
+               ], '', $this->l10n, $this->cache, $this->lock))->loadRoutes($routes);
 
                // Don't find GET
                self::assertEquals(Module\WellKnown\NodeInfo::class, $router->getModuleClass('/post/it'));