]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | declare(strict_types=1); | |
4 | ||
5 | namespace Shaarli\Container; | |
6 | ||
7 | use PHPUnit\Framework\TestCase; | |
8 | use Shaarli\Bookmark\BookmarkServiceInterface; | |
9 | use Shaarli\Config\ConfigManager; | |
10 | use Shaarli\Feed\FeedBuilder; | |
11 | use Shaarli\Formatter\FormatterFactory; | |
12 | use Shaarli\Front\Controller\Visitor\ErrorController; | |
13 | use Shaarli\History; | |
14 | use Shaarli\Http\HttpAccess; | |
15 | use Shaarli\Netscape\NetscapeBookmarkUtils; | |
16 | use Shaarli\Plugin\PluginManager; | |
17 | use Shaarli\Render\PageBuilder; | |
18 | use Shaarli\Render\PageCacheManager; | |
19 | use Shaarli\Security\CookieManager; | |
20 | use Shaarli\Security\LoginManager; | |
21 | use Shaarli\Security\SessionManager; | |
22 | use Shaarli\Thumbnailer; | |
23 | use Shaarli\Updater\Updater; | |
24 | use Slim\Http\Environment; | |
25 | ||
26 | class ContainerBuilderTest extends TestCase | |
27 | { | |
28 | /** @var ConfigManager */ | |
29 | protected $conf; | |
30 | ||
31 | /** @var SessionManager */ | |
32 | protected $sessionManager; | |
33 | ||
34 | /** @var LoginManager */ | |
35 | protected $loginManager; | |
36 | ||
37 | /** @var ContainerBuilder */ | |
38 | protected $containerBuilder; | |
39 | ||
40 | /** @var CookieManager */ | |
41 | protected $cookieManager; | |
42 | ||
43 | public function setUp(): void | |
44 | { | |
45 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | |
46 | $this->sessionManager = $this->createMock(SessionManager::class); | |
47 | $this->cookieManager = $this->createMock(CookieManager::class); | |
48 | ||
49 | $this->loginManager = $this->createMock(LoginManager::class); | |
50 | $this->loginManager->method('isLoggedIn')->willReturn(true); | |
51 | ||
52 | $this->containerBuilder = new ContainerBuilder( | |
53 | $this->conf, | |
54 | $this->sessionManager, | |
55 | $this->cookieManager, | |
56 | $this->loginManager | |
57 | ); | |
58 | } | |
59 | ||
60 | public function testBuildContainer(): void | |
61 | { | |
62 | $container = $this->containerBuilder->build(); | |
63 | ||
64 | static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); | |
65 | static::assertInstanceOf(CookieManager::class, $container->cookieManager); | |
66 | static::assertInstanceOf(ConfigManager::class, $container->conf); | |
67 | static::assertInstanceOf(ErrorController::class, $container->errorHandler); | |
68 | static::assertInstanceOf(Environment::class, $container->environment); | |
69 | static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder); | |
70 | static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory); | |
71 | static::assertInstanceOf(History::class, $container->history); | |
72 | static::assertInstanceOf(HttpAccess::class, $container->httpAccess); | |
73 | static::assertInstanceOf(LoginManager::class, $container->loginManager); | |
74 | static::assertInstanceOf(NetscapeBookmarkUtils::class, $container->netscapeBookmarkUtils); | |
75 | static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); | |
76 | static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager); | |
77 | static::assertInstanceOf(ErrorController::class, $container->phpErrorHandler); | |
78 | static::assertInstanceOf(PluginManager::class, $container->pluginManager); | |
79 | static::assertInstanceOf(SessionManager::class, $container->sessionManager); | |
80 | static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer); | |
81 | static::assertInstanceOf(Updater::class, $container->updater); | |
82 | ||
83 | // Set by the middleware | |
84 | static::assertNull($container->basePath); | |
85 | } | |
86 | } |