diff --git a/src/Controllers/HomeController.php b/src/Controllers/HomeController.php index e3989f81..521b7bdc 100644 --- a/src/Controllers/HomeController.php +++ b/src/Controllers/HomeController.php @@ -4,35 +4,37 @@ namespace Engelsystem\Controllers; use Engelsystem\Config\Config; use Engelsystem\Helpers\Authenticator; -use Engelsystem\Http\Exceptions\HttpTemporaryRedirect; +use Engelsystem\Http\Redirector; +use Engelsystem\Http\Response; class HomeController extends BaseController { - /** - * @var Authenticator - */ + /** @var Authenticator */ protected $auth; - /** - * @var Config - */ + /** @var Config */ protected $config; + /** @var Redirector */ + protected $redirect; + /** * @param Authenticator $auth * @param Config $config + * @param Redirector $redirect */ - public function __construct(Authenticator $auth, Config $config) + public function __construct(Authenticator $auth, Config $config, Redirector $redirect) { $this->auth = $auth; $this->config = $config; + $this->redirect = $redirect; } /** - * @throws HttpTemporaryRedirect + * @return Response */ - public function index() + public function index(): Response { - throw new HttpTemporaryRedirect($this->auth->user() ? $this->config->get('home_site') : 'login'); + return $this->redirect->to($this->auth->user() ? $this->config->get('home_site') : 'login'); } } diff --git a/tests/Unit/Controllers/HomeControllerTest.php b/tests/Unit/Controllers/HomeControllerTest.php index 56bb1995..b5205155 100644 --- a/tests/Unit/Controllers/HomeControllerTest.php +++ b/tests/Unit/Controllers/HomeControllerTest.php @@ -5,7 +5,8 @@ namespace Engelsystem\Test\Unit\Controllers; use Engelsystem\Config\Config; use Engelsystem\Controllers\HomeController; use Engelsystem\Helpers\Authenticator; -use Engelsystem\Http\Exceptions\HttpTemporaryRedirect; +use Engelsystem\Http\Redirector; +use Engelsystem\Http\Response; use Engelsystem\Test\Unit\TestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -21,10 +22,11 @@ class HomeControllerTest extends TestCase /** @var Authenticator|MockObject $auth */ $auth = $this->createMock(Authenticator::class); $this->setExpects($auth, 'user', null, true); + /** @var Redirector|MockObject $redirect */ + $redirect = $this->createMock(Redirector::class); + $this->setExpects($redirect, 'to', ['/foo'], new Response()); - $controller = new HomeController($auth, $config); - - $this->expectException(HttpTemporaryRedirect::class); + $controller = new HomeController($auth, $config, $redirect); $controller->index(); } }