Create a test container that we can use in any test

This commit is contained in:
Pierre Rudloff 2020-10-22 22:39:09 +02:00
parent d83774ae7d
commit 3d2b518cb4
16 changed files with 179 additions and 117 deletions

View file

@ -6,38 +6,24 @@
namespace Alltube\Test;
use Alltube\Exception\ConfigException;
use Alltube\Exception\DependencyException;
use Alltube\Factory\ConfigFactory;
use Alltube\Factory\LocaleManagerFactory;
use Alltube\Factory\SessionFactory;
use Alltube\Factory\ViewFactory;
use Slim\Container;
use Slim\Http\Environment;
use Slim\Http\Request;
use Slim\Views\Smarty;
use SmartyException;
/**
* Unit tests for the ViewFactory class.
*/
class ViewFactoryTest extends BaseTest
class ViewFactoryTest extends ContainerTest
{
/**
* Test the create() function.
*
* @return void
* @throws SmartyException
* @throws DependencyException
* @throws ConfigException
*/
public function testCreate()
{
$container = new Container();
$container['session'] = SessionFactory::create($container);
$container['locale'] = LocaleManagerFactory::create($container);
$container['config'] = ConfigFactory::create($container);
$view = ViewFactory::create($container);
$view = ViewFactory::create($this->container);
$this->assertInstanceOf(Smarty::class, $view);
}
@ -46,17 +32,13 @@ class ViewFactoryTest extends BaseTest
*
* @return void
* @throws SmartyException
* @throws DependencyException
* @throws ConfigException
*/
public function testCreateWithXForwardedProto()
{
$container = new Container();
$container['session'] = SessionFactory::create($container);
$container['locale'] = LocaleManagerFactory::create($container);
$container['config'] = ConfigFactory::create($container);
$request = Request::createFromEnvironment(Environment::mock());
$view = ViewFactory::create($container, $request->withHeader('X-Forwarded-Proto', 'https'));
$view = ViewFactory::create(
$this->container,
$this->container->get('request')->withHeader('X-Forwarded-Proto', 'https')
);
$this->assertInstanceOf(Smarty::class, $view);
}
}