From e06affae179dfeb41f77d8ad2ea81fa3f2fa439d Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 14 Jun 2019 04:05:38 +0200 Subject: Added tests to HomeController --- src/Controllers/HomeController.php | 24 ++++++++++++++++++++- tests/Unit/Controllers/HomeControllerTest.php | 30 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/Controllers/HomeControllerTest.php diff --git a/src/Controllers/HomeController.php b/src/Controllers/HomeController.php index 809593ce..e3989f81 100644 --- a/src/Controllers/HomeController.php +++ b/src/Controllers/HomeController.php @@ -2,15 +2,37 @@ namespace Engelsystem\Controllers; +use Engelsystem\Config\Config; +use Engelsystem\Helpers\Authenticator; use Engelsystem\Http\Exceptions\HttpTemporaryRedirect; class HomeController extends BaseController { + /** + * @var Authenticator + */ + protected $auth; + + /** + * @var Config + */ + protected $config; + + /** + * @param Authenticator $auth + * @param Config $config + */ + public function __construct(Authenticator $auth, Config $config) + { + $this->auth = $auth; + $this->config = $config; + } + /** * @throws HttpTemporaryRedirect */ public function index() { - throw new HttpTemporaryRedirect(auth()->user() ? config('home_site') : 'login'); + throw new HttpTemporaryRedirect($this->auth->user() ? $this->config->get('home_site') : 'login'); } } diff --git a/tests/Unit/Controllers/HomeControllerTest.php b/tests/Unit/Controllers/HomeControllerTest.php new file mode 100644 index 00000000..56bb1995 --- /dev/null +++ b/tests/Unit/Controllers/HomeControllerTest.php @@ -0,0 +1,30 @@ + '/foo']); + /** @var Authenticator|MockObject $auth */ + $auth = $this->createMock(Authenticator::class); + $this->setExpects($auth, 'user', null, true); + + $controller = new HomeController($auth, $config); + + $this->expectException(HttpTemporaryRedirect::class); + $controller->index(); + } +} -- cgit v1.2.3