Use test config for controller tests

This commit is contained in:
Pierre Rudloff 2017-04-24 17:49:13 +02:00
parent 2051ee410c
commit 2a31951217
2 changed files with 13 additions and 13 deletions

View File

@ -66,9 +66,13 @@ class FrontController
*
* @param Container $container Slim dependency container
*/
public function __construct(ContainerInterface $container)
public function __construct(ContainerInterface $container, Config $config = null)
{
$this->config = Config::getInstance();
if (isset($config)) {
$this->config = $config;
} else {
$this->config = Config::getInstance();
}
$this->download = new VideoDownload();
$this->container = $container;
$this->view = $this->container->get('view');

View File

@ -64,7 +64,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase
return $view;
};
$this->controller = new FrontController($this->container);
$this->controller = new FrontController($this->container, Config::getInstance('config_test.yml'));
$this->container['router']->map(['GET'], '/', [$this->controller, 'index'])
->setName('index');
$this->container['router']->map(['GET'], '/video', [$this->controller, 'video'])
@ -90,9 +90,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase
*/
public function testConstructorWithStream()
{
$config = Config::getInstance();
$config->stream = true;
$controller = new FrontController($this->container);
$controller = new FrontController($this->container, new Config(['stream'=>true]));
$this->assertInstanceOf(FrontController::class, $controller);
}
@ -242,14 +240,13 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase
*/
public function testVideoWithStream()
{
$config = Config::getInstance();
$config->stream = true;
$result = $this->controller->video(
$controller = new FrontController($this->container, new Config(['stream'=>true]));
$result = $controller->video(
$this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU']),
$this->response
);
$this->assertTrue($result->isOk());
$result = $this->controller->video(
$result = $controller->video(
$this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio'=>true]),
$this->response
);
@ -313,9 +310,8 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase
*/
public function testRedirectWithStream()
{
$config = Config::getInstance();
$config->stream = true;
$result = $this->controller->redirect(
$controller = new FrontController($this->container, new Config(['stream'=>true]));
$result = $controller->redirect(
$this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU']),
$this->response
);