aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/container
diff options
context:
space:
mode:
Diffstat (limited to 'tests/container')
-rw-r--r--tests/container/ContainerBuilderTest.php88
-rw-r--r--tests/container/ShaarliTestContainer.php42
2 files changed, 130 insertions, 0 deletions
diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php
new file mode 100644
index 00000000..5d52daef
--- /dev/null
+++ b/tests/container/ContainerBuilderTest.php
@@ -0,0 +1,88 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Container;
6
7use Shaarli\Bookmark\BookmarkServiceInterface;
8use Shaarli\Config\ConfigManager;
9use Shaarli\Feed\FeedBuilder;
10use Shaarli\Formatter\FormatterFactory;
11use Shaarli\Front\Controller\Visitor\ErrorController;
12use Shaarli\Front\Controller\Visitor\ErrorNotFoundController;
13use Shaarli\History;
14use Shaarli\Http\HttpAccess;
15use Shaarli\Netscape\NetscapeBookmarkUtils;
16use Shaarli\Plugin\PluginManager;
17use Shaarli\Render\PageBuilder;
18use Shaarli\Render\PageCacheManager;
19use Shaarli\Security\CookieManager;
20use Shaarli\Security\LoginManager;
21use Shaarli\Security\SessionManager;
22use Shaarli\TestCase;
23use Shaarli\Thumbnailer;
24use Shaarli\Updater\Updater;
25use Slim\Http\Environment;
26
27class ContainerBuilderTest extends TestCase
28{
29 /** @var ConfigManager */
30 protected $conf;
31
32 /** @var SessionManager */
33 protected $sessionManager;
34
35 /** @var LoginManager */
36 protected $loginManager;
37
38 /** @var ContainerBuilder */
39 protected $containerBuilder;
40
41 /** @var CookieManager */
42 protected $cookieManager;
43
44 public function setUp(): void
45 {
46 $this->conf = new ConfigManager('tests/utils/config/configJson');
47 $this->sessionManager = $this->createMock(SessionManager::class);
48 $this->cookieManager = $this->createMock(CookieManager::class);
49
50 $this->loginManager = $this->createMock(LoginManager::class);
51 $this->loginManager->method('isLoggedIn')->willReturn(true);
52
53 $this->containerBuilder = new ContainerBuilder(
54 $this->conf,
55 $this->sessionManager,
56 $this->cookieManager,
57 $this->loginManager
58 );
59 }
60
61 public function testBuildContainer(): void
62 {
63 $container = $this->containerBuilder->build();
64
65 static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService);
66 static::assertInstanceOf(CookieManager::class, $container->cookieManager);
67 static::assertInstanceOf(ConfigManager::class, $container->conf);
68 static::assertInstanceOf(ErrorController::class, $container->errorHandler);
69 static::assertInstanceOf(Environment::class, $container->environment);
70 static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder);
71 static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory);
72 static::assertInstanceOf(History::class, $container->history);
73 static::assertInstanceOf(HttpAccess::class, $container->httpAccess);
74 static::assertInstanceOf(LoginManager::class, $container->loginManager);
75 static::assertInstanceOf(NetscapeBookmarkUtils::class, $container->netscapeBookmarkUtils);
76 static::assertInstanceOf(PageBuilder::class, $container->pageBuilder);
77 static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager);
78 static::assertInstanceOf(ErrorController::class, $container->phpErrorHandler);
79 static::assertInstanceOf(ErrorNotFoundController::class, $container->notFoundHandler);
80 static::assertInstanceOf(PluginManager::class, $container->pluginManager);
81 static::assertInstanceOf(SessionManager::class, $container->sessionManager);
82 static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer);
83 static::assertInstanceOf(Updater::class, $container->updater);
84
85 // Set by the middleware
86 static::assertNull($container->basePath);
87 }
88}
diff --git a/tests/container/ShaarliTestContainer.php b/tests/container/ShaarliTestContainer.php
new file mode 100644
index 00000000..7dbe914c
--- /dev/null
+++ b/tests/container/ShaarliTestContainer.php
@@ -0,0 +1,42 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Container;
6
7use PHPUnit\Framework\MockObject\MockObject;
8use Shaarli\Bookmark\BookmarkServiceInterface;
9use Shaarli\Config\ConfigManager;
10use Shaarli\Feed\FeedBuilder;
11use Shaarli\Formatter\FormatterFactory;
12use Shaarli\History;
13use Shaarli\Http\HttpAccess;
14use Shaarli\Plugin\PluginManager;
15use Shaarli\Render\PageBuilder;
16use Shaarli\Render\PageCacheManager;
17use Shaarli\Security\LoginManager;
18use Shaarli\Security\SessionManager;
19use Shaarli\Thumbnailer;
20
21/**
22 * Test helper allowing auto-completion for MockObjects.
23 *
24 * @property mixed[] $environment $_SERVER automatically injected by Slim
25 * @property MockObject|ConfigManager $conf
26 * @property MockObject|SessionManager $sessionManager
27 * @property MockObject|LoginManager $loginManager
28 * @property MockObject|string $webPath
29 * @property MockObject|History $history
30 * @property MockObject|BookmarkServiceInterface $bookmarkService
31 * @property MockObject|PageBuilder $pageBuilder
32 * @property MockObject|PluginManager $pluginManager
33 * @property MockObject|FormatterFactory $formatterFactory
34 * @property MockObject|PageCacheManager $pageCacheManager
35 * @property MockObject|FeedBuilder $feedBuilder
36 * @property MockObject|Thumbnailer $thumbnailer
37 * @property MockObject|HttpAccess $httpAccess
38 */
39class ShaarliTestContainer extends ShaarliContainer
40{
41
42}