Added tests to HomeController
This commit is contained in:
parent
9232513831
commit
e06affae17
|
@ -2,15 +2,37 @@
|
||||||
|
|
||||||
namespace Engelsystem\Controllers;
|
namespace Engelsystem\Controllers;
|
||||||
|
|
||||||
|
use Engelsystem\Config\Config;
|
||||||
|
use Engelsystem\Helpers\Authenticator;
|
||||||
use Engelsystem\Http\Exceptions\HttpTemporaryRedirect;
|
use Engelsystem\Http\Exceptions\HttpTemporaryRedirect;
|
||||||
|
|
||||||
class HomeController extends BaseController
|
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
|
* @throws HttpTemporaryRedirect
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
throw new HttpTemporaryRedirect(auth()->user() ? config('home_site') : 'login');
|
throw new HttpTemporaryRedirect($this->auth->user() ? $this->config->get('home_site') : 'login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Test\Unit\Controllers;
|
||||||
|
|
||||||
|
use Engelsystem\Config\Config;
|
||||||
|
use Engelsystem\Controllers\HomeController;
|
||||||
|
use Engelsystem\Helpers\Authenticator;
|
||||||
|
use Engelsystem\Http\Exceptions\HttpTemporaryRedirect;
|
||||||
|
use Engelsystem\Test\Unit\TestCase;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
|
class HomeControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Controllers\HomeController::__construct
|
||||||
|
* @covers \Engelsystem\Controllers\HomeController::index
|
||||||
|
*/
|
||||||
|
public function testIndex()
|
||||||
|
{
|
||||||
|
$config = new Config(['home_site' => '/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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue