diff options
Diffstat (limited to 'tests/container')
-rw-r--r-- | tests/container/ContainerBuilderTest.php | 88 | ||||
-rw-r--r-- | tests/container/ShaarliTestContainer.php | 42 |
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 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Container; | ||
6 | |||
7 | use Shaarli\Bookmark\BookmarkServiceInterface; | ||
8 | use Shaarli\Config\ConfigManager; | ||
9 | use Shaarli\Feed\FeedBuilder; | ||
10 | use Shaarli\Formatter\FormatterFactory; | ||
11 | use Shaarli\Front\Controller\Visitor\ErrorController; | ||
12 | use Shaarli\Front\Controller\Visitor\ErrorNotFoundController; | ||
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\TestCase; | ||
23 | use Shaarli\Thumbnailer; | ||
24 | use Shaarli\Updater\Updater; | ||
25 | use Slim\Http\Environment; | ||
26 | |||
27 | class 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 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Container; | ||
6 | |||
7 | use PHPUnit\Framework\MockObject\MockObject; | ||
8 | use Shaarli\Bookmark\BookmarkServiceInterface; | ||
9 | use Shaarli\Config\ConfigManager; | ||
10 | use Shaarli\Feed\FeedBuilder; | ||
11 | use Shaarli\Formatter\FormatterFactory; | ||
12 | use Shaarli\History; | ||
13 | use Shaarli\Http\HttpAccess; | ||
14 | use Shaarli\Plugin\PluginManager; | ||
15 | use Shaarli\Render\PageBuilder; | ||
16 | use Shaarli\Render\PageCacheManager; | ||
17 | use Shaarli\Security\LoginManager; | ||
18 | use Shaarli\Security\SessionManager; | ||
19 | use 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 | */ | ||
39 | class ShaarliTestContainer extends ShaarliContainer | ||
40 | { | ||
41 | |||
42 | } | ||