From 2a31951217ad4fca9d92e21a8521b32e3392b150 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Mon, 24 Apr 2017 17:49:13 +0200 Subject: [PATCH] Use test config for controller tests --- controllers/FrontController.php | 8 ++++++-- tests/FrontControllerTest.php | 18 +++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 8c82779..3b45ece 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -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'); diff --git a/tests/FrontControllerTest.php b/tests/FrontControllerTest.php index 1d51e3d..db02b24 100644 --- a/tests/FrontControllerTest.php +++ b/tests/FrontControllerTest.php @@ -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 );