aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/container/ContainerBuilderTest.php
blob: 5d52daefd5f7cf0e8d62559ee19cd8853c9e8e6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php

declare(strict_types=1);

namespace Shaarli\Container;

use Shaarli\Bookmark\BookmarkServiceInterface;
use Shaarli\Config\ConfigManager;
use Shaarli\Feed\FeedBuilder;
use Shaarli\Formatter\FormatterFactory;
use Shaarli\Front\Controller\Visitor\ErrorController;
use Shaarli\Front\Controller\Visitor\ErrorNotFoundController;
use Shaarli\History;
use Shaarli\Http\HttpAccess;
use Shaarli\Netscape\NetscapeBookmarkUtils;
use Shaarli\Plugin\PluginManager;
use Shaarli\Render\PageBuilder;
use Shaarli\Render\PageCacheManager;
use Shaarli\Security\CookieManager;
use Shaarli\Security\LoginManager;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Shaarli\Thumbnailer;
use Shaarli\Updater\Updater;
use Slim\Http\Environment;

class ContainerBuilderTest extends TestCase
{
    /** @var ConfigManager */
    protected $conf;

    /** @var SessionManager */
    protected $sessionManager;

    /** @var LoginManager */
    protected $loginManager;

    /** @var ContainerBuilder */
    protected $containerBuilder;

    /** @var CookieManager */
    protected $cookieManager;

    public function setUp(): void
    {
        $this->conf = new ConfigManager('tests/utils/config/configJson');
        $this->sessionManager = $this->createMock(SessionManager::class);
        $this->cookieManager = $this->createMock(CookieManager::class);

        $this->loginManager = $this->createMock(LoginManager::class);
        $this->loginManager->method('isLoggedIn')->willReturn(true);

        $this->containerBuilder = new ContainerBuilder(
            $this->conf,
            $this->sessionManager,
            $this->cookieManager,
            $this->loginManager
        );
    }

    public function testBuildContainer(): void
    {
        $container = $this->containerBuilder->build();

        static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService);
        static::assertInstanceOf(CookieManager::class, $container->cookieManager);
        static::assertInstanceOf(ConfigManager::class, $container->conf);
        static::assertInstanceOf(ErrorController::class, $container->errorHandler);
        static::assertInstanceOf(Environment::class, $container->environment);
        static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder);
        static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory);
        static::assertInstanceOf(History::class, $container->history);
        static::assertInstanceOf(HttpAccess::class, $container->httpAccess);
        static::assertInstanceOf(LoginManager::class, $container->loginManager);
        static::assertInstanceOf(NetscapeBookmarkUtils::class, $container->netscapeBookmarkUtils);
        static::assertInstanceOf(PageBuilder::class, $container->pageBuilder);
        static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager);
        static::assertInstanceOf(ErrorController::class, $container->phpErrorHandler);
        static::assertInstanceOf(ErrorNotFoundController::class, $container->notFoundHandler);
        static::assertInstanceOf(PluginManager::class, $container->pluginManager);
        static::assertInstanceOf(SessionManager::class, $container->sessionManager);
        static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer);
        static::assertInstanceOf(Updater::class, $container->updater);

        // Set by the middleware
        static::assertNull($container->basePath);
    }
}