HomeController: Fix redirect
This commit is contained in:
parent
2e1fbfb16d
commit
ae744af814
|
@ -4,35 +4,37 @@ namespace Engelsystem\Controllers;
|
||||||
|
|
||||||
use Engelsystem\Config\Config;
|
use Engelsystem\Config\Config;
|
||||||
use Engelsystem\Helpers\Authenticator;
|
use Engelsystem\Helpers\Authenticator;
|
||||||
use Engelsystem\Http\Exceptions\HttpTemporaryRedirect;
|
use Engelsystem\Http\Redirector;
|
||||||
|
use Engelsystem\Http\Response;
|
||||||
|
|
||||||
class HomeController extends BaseController
|
class HomeController extends BaseController
|
||||||
{
|
{
|
||||||
/**
|
/** @var Authenticator */
|
||||||
* @var Authenticator
|
|
||||||
*/
|
|
||||||
protected $auth;
|
protected $auth;
|
||||||
|
|
||||||
/**
|
/** @var Config */
|
||||||
* @var Config
|
|
||||||
*/
|
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
/** @var Redirector */
|
||||||
|
protected $redirect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Authenticator $auth
|
* @param Authenticator $auth
|
||||||
* @param Config $config
|
* @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->auth = $auth;
|
||||||
$this->config = $config;
|
$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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ namespace Engelsystem\Test\Unit\Controllers;
|
||||||
use Engelsystem\Config\Config;
|
use Engelsystem\Config\Config;
|
||||||
use Engelsystem\Controllers\HomeController;
|
use Engelsystem\Controllers\HomeController;
|
||||||
use Engelsystem\Helpers\Authenticator;
|
use Engelsystem\Helpers\Authenticator;
|
||||||
use Engelsystem\Http\Exceptions\HttpTemporaryRedirect;
|
use Engelsystem\Http\Redirector;
|
||||||
|
use Engelsystem\Http\Response;
|
||||||
use Engelsystem\Test\Unit\TestCase;
|
use Engelsystem\Test\Unit\TestCase;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
|
@ -21,10 +22,11 @@ class HomeControllerTest extends TestCase
|
||||||
/** @var Authenticator|MockObject $auth */
|
/** @var Authenticator|MockObject $auth */
|
||||||
$auth = $this->createMock(Authenticator::class);
|
$auth = $this->createMock(Authenticator::class);
|
||||||
$this->setExpects($auth, 'user', null, true);
|
$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);
|
$controller = new HomeController($auth, $config, $redirect);
|
||||||
|
|
||||||
$this->expectException(HttpTemporaryRedirect::class);
|
|
||||||
$controller->index();
|
$controller->index();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue