Convert SessionManager to a factory class
This commit is contained in:
parent
5b0ee7651b
commit
de8c5e5dc7
10 changed files with 64 additions and 52 deletions
|
@ -11,6 +11,9 @@ use Alltube\Controller\BaseController;
|
|||
use Alltube\Controller\DownloadController;
|
||||
use Alltube\Controller\FrontController;
|
||||
use Alltube\Exception\ConfigException;
|
||||
use Alltube\Exception\DependencyException;
|
||||
use Alltube\Factory\LocaleManagerFactory;
|
||||
use Alltube\Factory\SessionFactory;
|
||||
use Alltube\Factory\ViewFactory;
|
||||
use Alltube\LocaleManager;
|
||||
use Psr\Log\NullLogger;
|
||||
|
@ -55,6 +58,7 @@ abstract class ControllerTest extends BaseTest
|
|||
/**
|
||||
* Prepare tests.
|
||||
* @throws ConfigException|SmartyException
|
||||
* @throws DependencyException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
@ -64,7 +68,8 @@ abstract class ControllerTest extends BaseTest
|
|||
$this->request = Request::createFromEnvironment(Environment::mock());
|
||||
$this->response = new Response();
|
||||
$this->container['config'] = Config::fromFile($this->getConfigFile());
|
||||
$this->container['locale'] = new LocaleManager();
|
||||
$this->container['session'] = SessionFactory::create();
|
||||
$this->container['locale'] = LocaleManagerFactory::create($this->container);
|
||||
$this->container['view'] = ViewFactory::create($this->container, $this->request);
|
||||
$this->container['logger'] = new NullLogger();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Factory\SessionFactory;
|
||||
use Alltube\Locale;
|
||||
use Alltube\LocaleManager;
|
||||
|
||||
|
@ -27,7 +28,7 @@ class LocaleManagerTest extends BaseTest
|
|||
protected function setUp(): void
|
||||
{
|
||||
$_SESSION[LocaleManager::class]['locale'] = 'foo_BAR';
|
||||
$this->localeManager = new LocaleManager();
|
||||
$this->localeManager = new LocaleManager(SessionFactory::create());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\LocaleManager;
|
||||
use Alltube\Exception\DependencyException;
|
||||
use Alltube\Factory\LocaleManagerFactory;
|
||||
use Alltube\Factory\SessionFactory;
|
||||
use Alltube\Middleware\LocaleMiddleware;
|
||||
use Slim\Container;
|
||||
use Slim\Http\Environment;
|
||||
|
@ -34,11 +36,13 @@ class LocaleMiddlewareTest extends BaseTest
|
|||
|
||||
/**
|
||||
* Prepare tests.
|
||||
* @throws DependencyException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->container = new Container();
|
||||
$this->container['locale'] = new LocaleManager();
|
||||
$this->container['session'] = SessionFactory::create();
|
||||
$this->container['locale'] = LocaleManagerFactory::create($this->container);
|
||||
$this->middleware = new LocaleMiddleware($this->container);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
|
||||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Exception\DependencyException;
|
||||
use Alltube\Factory\LocaleManagerFactory;
|
||||
use Alltube\Factory\SessionFactory;
|
||||
use Alltube\Factory\ViewFactory;
|
||||
use Alltube\LocaleManager;
|
||||
use Slim\Container;
|
||||
use Slim\Http\Environment;
|
||||
use Slim\Http\Request;
|
||||
|
@ -24,11 +26,13 @@ class ViewFactoryTest extends BaseTest
|
|||
*
|
||||
* @return void
|
||||
* @throws SmartyException
|
||||
* @throws DependencyException
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
$container = new Container();
|
||||
$container['locale'] = new LocaleManager();
|
||||
$container['session'] = SessionFactory::create();
|
||||
$container['locale'] = LocaleManagerFactory::create($container);
|
||||
$view = ViewFactory::create($container);
|
||||
$this->assertInstanceOf(Smarty::class, $view);
|
||||
}
|
||||
|
@ -38,11 +42,13 @@ class ViewFactoryTest extends BaseTest
|
|||
*
|
||||
* @return void
|
||||
* @throws SmartyException
|
||||
* @throws DependencyException
|
||||
*/
|
||||
public function testCreateWithXForwardedProto()
|
||||
{
|
||||
$container = new Container();
|
||||
$container['locale'] = new LocaleManager();
|
||||
$container['session'] = SessionFactory::create();
|
||||
$container['locale'] = LocaleManagerFactory::create($container);
|
||||
$request = Request::createFromEnvironment(Environment::mock());
|
||||
$view = ViewFactory::create($container, $request->withHeader('X-Forwarded-Proto', 'https'));
|
||||
$this->assertInstanceOf(Smarty::class, $view);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue