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 * @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->download = new VideoDownload();
$this->container = $container; $this->container = $container;
$this->view = $this->container->get('view'); $this->view = $this->container->get('view');

View file

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