2020-01-18 17:50:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shaarli\Container;
|
|
|
|
|
|
|
|
use Shaarli\Bookmark\BookmarkServiceInterface;
|
|
|
|
use Shaarli\Config\ConfigManager;
|
2020-06-13 13:08:01 +02:00
|
|
|
use Shaarli\Feed\FeedBuilder;
|
2020-01-26 11:15:15 +01:00
|
|
|
use Shaarli\Formatter\FormatterFactory;
|
2020-08-27 12:04:36 +02:00
|
|
|
use Shaarli\Front\Controller\Visitor\ErrorController;
|
2020-09-12 12:42:19 +02:00
|
|
|
use Shaarli\Front\Controller\Visitor\ErrorNotFoundController;
|
2020-01-18 17:50:11 +01:00
|
|
|
use Shaarli\History;
|
2020-06-13 13:08:01 +02:00
|
|
|
use Shaarli\Http\HttpAccess;
|
2020-09-25 13:29:36 +02:00
|
|
|
use Shaarli\Http\MetadataRetriever;
|
2020-07-07 10:15:56 +02:00
|
|
|
use Shaarli\Netscape\NetscapeBookmarkUtils;
|
2020-06-13 13:08:01 +02:00
|
|
|
use Shaarli\Plugin\PluginManager;
|
2020-01-18 17:50:11 +01:00
|
|
|
use Shaarli\Render\PageBuilder;
|
2020-01-23 21:52:03 +01:00
|
|
|
use Shaarli\Render\PageCacheManager;
|
2020-07-07 10:15:56 +02:00
|
|
|
use Shaarli\Security\CookieManager;
|
2020-01-18 17:50:11 +01:00
|
|
|
use Shaarli\Security\LoginManager;
|
|
|
|
use Shaarli\Security\SessionManager;
|
2020-09-29 14:41:40 +02:00
|
|
|
use Shaarli\TestCase;
|
2020-06-13 13:08:01 +02:00
|
|
|
use Shaarli\Thumbnailer;
|
2020-07-07 10:15:56 +02:00
|
|
|
use Shaarli\Updater\Updater;
|
2020-08-27 12:04:36 +02:00
|
|
|
use Slim\Http\Environment;
|
2020-01-18 17:50:11 +01:00
|
|
|
|
|
|
|
class ContainerBuilderTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @var ConfigManager */
|
|
|
|
protected $conf;
|
|
|
|
|
|
|
|
/** @var SessionManager */
|
|
|
|
protected $sessionManager;
|
|
|
|
|
|
|
|
/** @var LoginManager */
|
|
|
|
protected $loginManager;
|
|
|
|
|
|
|
|
/** @var ContainerBuilder */
|
|
|
|
protected $containerBuilder;
|
|
|
|
|
2020-07-07 10:15:56 +02:00
|
|
|
/** @var CookieManager */
|
|
|
|
protected $cookieManager;
|
|
|
|
|
2020-01-18 17:50:11 +01:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
|
|
|
$this->sessionManager = $this->createMock(SessionManager::class);
|
2020-07-07 10:15:56 +02:00
|
|
|
$this->cookieManager = $this->createMock(CookieManager::class);
|
2020-01-26 11:15:15 +01:00
|
|
|
|
2020-01-18 17:50:11 +01:00
|
|
|
$this->loginManager = $this->createMock(LoginManager::class);
|
2020-01-26 11:15:15 +01:00
|
|
|
$this->loginManager->method('isLoggedIn')->willReturn(true);
|
2020-01-18 17:50:11 +01:00
|
|
|
|
2020-01-23 21:52:03 +01:00
|
|
|
$this->containerBuilder = new ContainerBuilder(
|
|
|
|
$this->conf,
|
|
|
|
$this->sessionManager,
|
2020-07-07 10:15:56 +02:00
|
|
|
$this->cookieManager,
|
2020-06-13 13:08:01 +02:00
|
|
|
$this->loginManager
|
2020-01-23 21:52:03 +01:00
|
|
|
);
|
2020-01-18 17:50:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testBuildContainer(): void
|
|
|
|
{
|
|
|
|
$container = $this->containerBuilder->build();
|
|
|
|
|
2020-08-27 12:04:36 +02:00
|
|
|
static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService);
|
2020-07-07 10:15:56 +02:00
|
|
|
static::assertInstanceOf(CookieManager::class, $container->cookieManager);
|
2020-08-27 12:04:36 +02:00
|
|
|
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);
|
2020-01-18 17:50:11 +01:00
|
|
|
static::assertInstanceOf(History::class, $container->history);
|
2020-08-27 12:04:36 +02:00
|
|
|
static::assertInstanceOf(HttpAccess::class, $container->httpAccess);
|
|
|
|
static::assertInstanceOf(LoginManager::class, $container->loginManager);
|
2020-09-25 13:29:36 +02:00
|
|
|
static::assertInstanceOf(MetadataRetriever::class, $container->metadataRetriever);
|
2020-08-27 12:04:36 +02:00
|
|
|
static::assertInstanceOf(NetscapeBookmarkUtils::class, $container->netscapeBookmarkUtils);
|
2020-01-18 17:50:11 +01:00
|
|
|
static::assertInstanceOf(PageBuilder::class, $container->pageBuilder);
|
2020-01-23 21:52:03 +01:00
|
|
|
static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager);
|
2020-08-27 12:04:36 +02:00
|
|
|
static::assertInstanceOf(ErrorController::class, $container->phpErrorHandler);
|
2020-09-12 12:42:19 +02:00
|
|
|
static::assertInstanceOf(ErrorNotFoundController::class, $container->notFoundHandler);
|
2020-08-27 12:04:36 +02:00
|
|
|
static::assertInstanceOf(PluginManager::class, $container->pluginManager);
|
|
|
|
static::assertInstanceOf(SessionManager::class, $container->sessionManager);
|
2020-06-13 13:08:01 +02:00
|
|
|
static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer);
|
2020-07-07 10:15:56 +02:00
|
|
|
static::assertInstanceOf(Updater::class, $container->updater);
|
2020-06-13 13:08:01 +02:00
|
|
|
|
|
|
|
// Set by the middleware
|
|
|
|
static::assertNull($container->basePath);
|
2020-01-18 17:50:11 +01:00
|
|
|
}
|
|
|
|
}
|