X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Ffront%2Fcontroller%2Fvisitor%2FFrontControllerMockHelper.php;h=02229f68026dca2a8934612de915d9d3020dded6;hb=b3bd8c3e8d367975980043e772f7cd78b7f96bc6;hp=bc3266b5ce2409ee80bbc072ef88877e3052d16c;hpb=2899ebb5b5e82890c877151f5c02045266ac9973;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/front/controller/visitor/FrontControllerMockHelper.php b/tests/front/controller/visitor/FrontControllerMockHelper.php index bc3266b5..02229f68 100644 --- a/tests/front/controller/visitor/FrontControllerMockHelper.php +++ b/tests/front/controller/visitor/FrontControllerMockHelper.php @@ -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; }