aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/FeedControllerTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-05-20 12:43:40 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commitdd09ec52b20b4a548ecf5c847627575e506e3a50 (patch)
treeb598b84727df2c604622b4db1dfee831dc7c5dca /tests/front/controller/FeedControllerTest.php
parent5ec4708ced1cdca01eddd7e52377ab5e5f8b3290 (diff)
downloadShaarli-dd09ec52b20b4a548ecf5c847627575e506e3a50.tar.gz
Shaarli-dd09ec52b20b4a548ecf5c847627575e506e3a50.tar.zst
Shaarli-dd09ec52b20b4a548ecf5c847627575e506e3a50.zip
Refactor front controller tests to create container mock using a trait
Diffstat (limited to 'tests/front/controller/FeedControllerTest.php')
-rw-r--r--tests/front/controller/FeedControllerTest.php78
1 files changed, 5 insertions, 73 deletions
diff --git a/tests/front/controller/FeedControllerTest.php b/tests/front/controller/FeedControllerTest.php
index d4cc5536..7e8657e2 100644
--- a/tests/front/controller/FeedControllerTest.php
+++ b/tests/front/controller/FeedControllerTest.php
@@ -5,29 +5,23 @@ declare(strict_types=1);
5namespace Shaarli\Front\Controller; 5namespace Shaarli\Front\Controller;
6 6
7use PHPUnit\Framework\TestCase; 7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\BookmarkServiceInterface;
9use Shaarli\Config\ConfigManager;
10use Shaarli\Container\ShaarliContainer;
11use Shaarli\Feed\FeedBuilder; 8use Shaarli\Feed\FeedBuilder;
12use Shaarli\Formatter\FormatterFactory;
13use Shaarli\Plugin\PluginManager;
14use Shaarli\Render\PageBuilder;
15use Shaarli\Render\PageCacheManager;
16use Shaarli\Security\LoginManager;
17use Slim\Http\Request; 9use Slim\Http\Request;
18use Slim\Http\Response; 10use Slim\Http\Response;
19 11
20class FeedControllerTest extends TestCase 12class FeedControllerTest extends TestCase
21{ 13{
22 /** @var ShaarliContainer */ 14 use FrontControllerMockHelper;
23 protected $container;
24 15
25 /** @var FeedController */ 16 /** @var FeedController */
26 protected $controller; 17 protected $controller;
27 18
28 public function setUp(): void 19 public function setUp(): void
29 { 20 {
30 $this->container = $this->createMock(ShaarliContainer::class); 21 $this->createContainer();
22
23 $this->container->feedBuilder = $this->createMock(FeedBuilder::class);
24
31 $this->controller = new FeedController($this->container); 25 $this->controller = new FeedController($this->container);
32 } 26 }
33 27
@@ -154,66 +148,4 @@ class FeedControllerTest extends TestCase
154 static::assertSame('feed.atom', (string) $result->getBody()); 148 static::assertSame('feed.atom', (string) $result->getBody());
155 static::assertSame('data', $assignedVariables['content']); 149 static::assertSame('data', $assignedVariables['content']);
156 } 150 }
157
158 protected function createValidContainerMockSet(): void
159 {
160 $loginManager = $this->createMock(LoginManager::class);
161 $this->container->loginManager = $loginManager;
162
163 // Config
164 $conf = $this->createMock(ConfigManager::class);
165 $this->container->conf = $conf;
166 $this->container->conf->method('get')->willReturnCallback(function (string $parameter, $default) {
167 return $default;
168 });
169
170 // PageBuilder
171 $pageBuilder = $this->createMock(PageBuilder::class);
172 $pageBuilder
173 ->method('render')
174 ->willReturnCallback(function (string $template): string {
175 return $template;
176 })
177 ;
178 $this->container->pageBuilder = $pageBuilder;
179
180 $bookmarkService = $this->createMock(BookmarkServiceInterface::class);
181 $this->container->bookmarkService = $bookmarkService;
182
183 // Plugin Manager
184 $pluginManager = $this->createMock(PluginManager::class);
185 $this->container->pluginManager = $pluginManager;
186
187 // Formatter
188 $formatterFactory = $this->createMock(FormatterFactory::class);
189 $this->container->formatterFactory = $formatterFactory;
190
191 // CacheManager
192 $pageCacheManager = $this->createMock(PageCacheManager::class);
193 $this->container->pageCacheManager = $pageCacheManager;
194
195 // FeedBuilder
196 $feedBuilder = $this->createMock(FeedBuilder::class);
197 $this->container->feedBuilder = $feedBuilder;
198
199 // $_SERVER
200 $this->container->environment = [
201 'SERVER_NAME' => 'shaarli',
202 'SERVER_PORT' => '80',
203 'REQUEST_URI' => '/daily-rss',
204 ];
205 }
206
207 protected function assignTemplateVars(array &$variables): void
208 {
209 $this->container->pageBuilder
210 ->expects(static::atLeastOnce())
211 ->method('assign')
212 ->willReturnCallback(function ($key, $value) use (&$variables) {
213 $variables[$key] = $value;
214
215 return $this;
216 })
217 ;
218 }
219} 151}