X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=tests%2Ffront%2Fcontroller%2FDailyControllerTest.php;h=7ec99030c8e838e15c7943f651b4572ae320bfb6;hb=dd09ec52b20b4a548ecf5c847627575e506e3a50;hp=88ec116bac509ec89ba29ff0915da5e3200051d1;hpb=5ec4708ced1cdca01eddd7e52377ab5e5f8b3290;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/front/controller/DailyControllerTest.php b/tests/front/controller/DailyControllerTest.php index 88ec116b..7ec99030 100644 --- a/tests/front/controller/DailyControllerTest.php +++ b/tests/front/controller/DailyControllerTest.php @@ -6,31 +6,21 @@ namespace Shaarli\Front\Controller; use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\Bookmark; -use Shaarli\Bookmark\BookmarkServiceInterface; -use Shaarli\Config\ConfigManager; -use Shaarli\Container\ShaarliContainer; use Shaarli\Feed\CachedPage; -use Shaarli\Formatter\BookmarkFormatter; -use Shaarli\Formatter\BookmarkRawFormatter; -use Shaarli\Formatter\FormatterFactory; -use Shaarli\Plugin\PluginManager; -use Shaarli\Render\PageBuilder; -use Shaarli\Render\PageCacheManager; -use Shaarli\Security\LoginManager; use Slim\Http\Request; use Slim\Http\Response; class DailyControllerTest extends TestCase { - /** @var ShaarliContainer */ - protected $container; + use FrontControllerMockHelper; /** @var DailyController */ protected $controller; public function setUp(): void { - $this->container = $this->createMock(ShaarliContainer::class); + $this->createContainer(); + $this->controller = new DailyController($this->container); DailyController::$DAILY_RSS_NB_DAYS = 2; } @@ -105,7 +95,8 @@ class DailyControllerTest extends TestCase static::assertArrayHasKey('loggedin', $param); return $data; - }); + }) + ; $result = $this->controller->index($request, $response); @@ -497,71 +488,6 @@ class DailyControllerTest extends TestCase static::assertCount(0, $assignedVariables['days']); } - protected function createValidContainerMockSet(): void - { - $loginManager = $this->createMock(LoginManager::class); - $this->container->loginManager = $loginManager; - - // Config - $conf = $this->createMock(ConfigManager::class); - $this->container->conf = $conf; - $this->container->conf->method('get')->willReturnCallback(function (string $parameter, $default) { - return $default; - }); - - // PageBuilder - $pageBuilder = $this->createMock(PageBuilder::class); - $pageBuilder - ->method('render') - ->willReturnCallback(function (string $template): string { - return $template; - }) - ; - $this->container->pageBuilder = $pageBuilder; - - // Plugin Manager - $pluginManager = $this->createMock(PluginManager::class); - $this->container->pluginManager = $pluginManager; - - // BookmarkService - $bookmarkService = $this->createMock(BookmarkServiceInterface::class); - $this->container->bookmarkService = $bookmarkService; - - // Formatter - $formatterFactory = $this->createMock(FormatterFactory::class); - $formatterFactory - ->method('getFormatter') - ->willReturnCallback(function (): BookmarkFormatter { - return new BookmarkRawFormatter($this->container->conf, true); - }) - ; - $this->container->formatterFactory = $formatterFactory; - - // CacheManager - $pageCacheManager = $this->createMock(PageCacheManager::class); - $this->container->pageCacheManager = $pageCacheManager; - - // $_SERVER - $this->container->environment = [ - 'SERVER_NAME' => 'shaarli', - 'SERVER_PORT' => '80', - 'REQUEST_URI' => '/daily-rss', - ]; - } - - protected function assignTemplateVars(array &$variables): void - { - $this->container->pageBuilder - ->expects(static::atLeastOnce()) - ->method('assign') - ->willReturnCallback(function ($key, $value) use (&$variables) { - $variables[$key] = $value; - - return $this; - }) - ; - } - protected static function generateContent(int $length): string { // bin2hex(random_bytes) generates string twice as long as given parameter