diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-05-20 12:43:40 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | dd09ec52b20b4a548ecf5c847627575e506e3a50 (patch) | |
tree | b598b84727df2c604622b4db1dfee831dc7c5dca /tests/front/controller/FeedControllerTest.php | |
parent | 5ec4708ced1cdca01eddd7e52377ab5e5f8b3290 (diff) | |
download | Shaarli-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.php | 78 |
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); | |||
5 | namespace Shaarli\Front\Controller; | 5 | namespace Shaarli\Front\Controller; |
6 | 6 | ||
7 | use PHPUnit\Framework\TestCase; | 7 | use PHPUnit\Framework\TestCase; |
8 | use Shaarli\Bookmark\BookmarkServiceInterface; | ||
9 | use Shaarli\Config\ConfigManager; | ||
10 | use Shaarli\Container\ShaarliContainer; | ||
11 | use Shaarli\Feed\FeedBuilder; | 8 | use Shaarli\Feed\FeedBuilder; |
12 | use Shaarli\Formatter\FormatterFactory; | ||
13 | use Shaarli\Plugin\PluginManager; | ||
14 | use Shaarli\Render\PageBuilder; | ||
15 | use Shaarli\Render\PageCacheManager; | ||
16 | use Shaarli\Security\LoginManager; | ||
17 | use Slim\Http\Request; | 9 | use Slim\Http\Request; |
18 | use Slim\Http\Response; | 10 | use Slim\Http\Response; |
19 | 11 | ||
20 | class FeedControllerTest extends TestCase | 12 | class 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 | } |