]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/front/controller/visitor/FrontControllerMockHelper.php
Feature: support any tag separator
[github/shaarli/Shaarli.git] / tests / front / controller / visitor / FrontControllerMockHelper.php
index bc3266b5ce2409ee80bbc072ef88877e3052d16c..02229f68026dca2a8934612de915d9d3020dded6 100644 (file)
@@ -4,7 +4,6 @@ declare(strict_types=1);
 
 namespace Shaarli\Front\Controller\Visitor;
 
-use PHPUnit\Framework\MockObject\MockObject;
 use Shaarli\Bookmark\BookmarkServiceInterface;
 use Shaarli\Config\ConfigManager;
 use Shaarli\Container\ShaarliTestContainer;
@@ -31,24 +30,22 @@ trait FrontControllerMockHelper
     protected $container;
 
     /**
-     * Mock the container instance
+     * Mock the container instance and initialize container's services used by tests
      */
     protected function createContainer(): void
     {
         $this->container = $this->createMock(ShaarliTestContainer::class);
-    }
 
-    /**
-     * Initialize container's services used by tests
-     */
-    protected function createValidContainerMockSet(): void
-    {
         $this->container->loginManager = $this->createMock(LoginManager::class);
 
         // Config
         $this->container->conf = $this->createMock(ConfigManager::class);
         $this->container->conf->method('get')->willReturnCallback(function (string $parameter, $default) {
-            return $default;
+            if ($parameter === 'general.tags_separator') {
+                return '@';
+            }
+
+            return $default === null ? $parameter : $default;
         });
 
         // PageBuilder
@@ -85,8 +82,12 @@ trait FrontControllerMockHelper
         $this->container->environment = [
             'SERVER_NAME' => 'shaarli',
             'SERVER_PORT' => '80',
-            'REQUEST_URI' => '/daily-rss',
+            'REQUEST_URI' => '/subfolder/daily-rss',
+            'REMOTE_ADDR' => '1.2.3.4',
+            'SCRIPT_NAME' => '/subfolder/index.php',
         ];
+
+        $this->container->basePath = '/subfolder';
     }
 
     /**
@@ -97,7 +98,6 @@ trait FrontControllerMockHelper
     protected function assignTemplateVars(array &$variables): void
     {
         $this->container->pageBuilder
-            ->expects(static::atLeastOnce())
             ->method('assign')
             ->willReturnCallback(function ($key, $value) use (&$variables) {
                 $variables[$key] = $value;
@@ -107,8 +107,16 @@ trait FrontControllerMockHelper
         ;
     }
 
+    protected static function generateString(int $length): string
+    {
+        // bin2hex(random_bytes) generates string twice as long as given parameter
+        $length = (int) ceil($length / 2);
+
+        return bin2hex(random_bytes($length));
+    }
+
     /**
      * Force to be used in PHPUnit context.
      */
-    protected abstract function createMock($originalClassName): MockObject;
+    protected abstract function isInTestsContext(): bool;
 }