2020-01-18 17:50:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shaarli\Container;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
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-01-18 17:50:11 +01:00
|
|
|
use Shaarli\History;
|
2020-06-13 13:08:01 +02:00
|
|
|
use Shaarli\Http\HttpAccess;
|
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-06-13 13:08:01 +02:00
|
|
|
use Shaarli\Thumbnailer;
|
2020-07-07 10:15:56 +02:00
|
|
|
use Shaarli\Updater\Updater;
|
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();
|
|
|
|
|
|
|
|
static::assertInstanceOf(ConfigManager::class, $container->conf);
|
|
|
|
static::assertInstanceOf(SessionManager::class, $container->sessionManager);
|
2020-07-07 10:15:56 +02:00
|
|
|
static::assertInstanceOf(CookieManager::class, $container->cookieManager);
|
2020-01-18 17:50:11 +01:00
|
|
|
static::assertInstanceOf(LoginManager::class, $container->loginManager);
|
|
|
|
static::assertInstanceOf(History::class, $container->history);
|
|
|
|
static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService);
|
|
|
|
static::assertInstanceOf(PageBuilder::class, $container->pageBuilder);
|
2020-06-13 13:08:01 +02:00
|
|
|
static::assertInstanceOf(PluginManager::class, $container->pluginManager);
|
2020-01-26 11:15:15 +01:00
|
|
|
static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory);
|
2020-01-23 21:52:03 +01:00
|
|
|
static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager);
|
2020-06-13 13:08:01 +02:00
|
|
|
static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder);
|
|
|
|
static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer);
|
|
|
|
static::assertInstanceOf(HttpAccess::class, $container->httpAccess);
|
2020-07-07 10:15:56 +02:00
|
|
|
static::assertInstanceOf(NetscapeBookmarkUtils::class, $container->netscapeBookmarkUtils);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|