diff --git a/classes/LocaleManager.php b/classes/LocaleManager.php index 70fdd6f..0b7032a 100644 --- a/classes/LocaleManager.php +++ b/classes/LocaleManager.php @@ -168,4 +168,14 @@ class LocaleManager return self::$instance; } + + /** + * Destroy singleton instance. + * + * @return void + */ + public static function destroyInstance() + { + self::$instance = null; + } } diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index fa6b02c..c703a7d 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -56,8 +56,8 @@ abstract class ControllerTest extends BaseTest $this->container = new Container(); $this->request = Request::createFromEnvironment(Environment::mock()); $this->response = new Response(); + $this->container['locale'] = LocaleManager::getInstance(); $this->container['view'] = ViewFactory::create($this->container, $this->request); - $this->container['locale'] = new LocaleManager(); $frontController = new FrontController($this->container); $downloadController = new DownloadController($this->container); diff --git a/tests/LocaleManagerTest.php b/tests/LocaleManagerTest.php index 1bbc8a1..1ceb5d8 100644 --- a/tests/LocaleManagerTest.php +++ b/tests/LocaleManagerTest.php @@ -27,7 +27,7 @@ class LocaleManagerTest extends BaseTest protected function setUp() { $_SESSION[LocaleManager::class]['locale'] = 'foo_BAR'; - $this->localeManager = new LocaleManager(); + $this->localeManager = LocaleManager::getInstance(); } /** @@ -38,6 +38,7 @@ class LocaleManagerTest extends BaseTest protected function tearDown() { $this->localeManager->unsetLocale(); + LocaleManager::destroyInstance(); } /** @@ -93,6 +94,7 @@ class LocaleManagerTest extends BaseTest */ public function testEnv() { + putenv('LANG=foo_BAR'); $this->localeManager->setLocale(new Locale('foo_BAR')); $this->assertEquals('foo_BAR', getenv('LANG')); } diff --git a/tests/LocaleMiddlewareTest.php b/tests/LocaleMiddlewareTest.php index 299e8ca..005e87e 100644 --- a/tests/LocaleMiddlewareTest.php +++ b/tests/LocaleMiddlewareTest.php @@ -39,7 +39,7 @@ class LocaleMiddlewareTest extends BaseTest protected function setUp() { $this->container = new Container(); - $this->container['locale'] = new LocaleManager(); + $this->container['locale'] = LocaleManager::getInstance(); $this->middleware = new LocaleMiddleware($this->container); } @@ -51,6 +51,7 @@ class LocaleMiddlewareTest extends BaseTest protected function tearDown() { $this->container['locale']->unsetLocale(); + LocaleManager::destroyInstance(); } /** diff --git a/tests/ViewFactoryTest.php b/tests/ViewFactoryTest.php index 163eeb1..45286c9 100644 --- a/tests/ViewFactoryTest.php +++ b/tests/ViewFactoryTest.php @@ -6,6 +6,7 @@ namespace Alltube\Test; +use Alltube\LocaleManager; use Alltube\ViewFactory; use Slim\Container; use Slim\Http\Environment; @@ -24,7 +25,9 @@ class ViewFactoryTest extends BaseTest */ public function testCreate() { - $view = ViewFactory::create(new Container()); + $container = new Container(); + $container['locale'] = LocaleManager::getInstance(); + $view = ViewFactory::create($container); $this->assertInstanceOf(Smarty::class, $view); } @@ -35,8 +38,10 @@ class ViewFactoryTest extends BaseTest */ public function testCreateWithXForwardedProto() { + $container = new Container(); + $container['locale'] = LocaleManager::getInstance(); $request = Request::createFromEnvironment(Environment::mock()); - $view = ViewFactory::create(new Container(), $request->withHeader('X-Forwarded-Proto', 'https')); + $view = ViewFactory::create($container, $request->withHeader('X-Forwarded-Proto', 'https')); $this->assertInstanceOf(Smarty::class, $view); } }