|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Controllers;
|
|
|
|
namespace Engelsystem\Test\Unit\Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use Engelsystem\Controllers\AuthController;
|
|
|
|
use Engelsystem\Controllers\AuthController;
|
|
|
|
use Engelsystem\Helpers\Authenticator;
|
|
|
|
use Engelsystem\Helpers\Authenticator;
|
|
|
@ -21,6 +22,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
|
|
|
|
|
|
|
|
|
|
|
class AuthControllerTest extends TestCase
|
|
|
|
class AuthControllerTest extends TestCase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
use ArraySubsetAsserts;
|
|
|
|
use HasDatabase;
|
|
|
|
use HasDatabase;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -38,10 +40,11 @@ class AuthControllerTest extends TestCase
|
|
|
|
/** @var Authenticator|MockObject $auth */
|
|
|
|
/** @var Authenticator|MockObject $auth */
|
|
|
|
list(, $session, $url, $config, $auth) = $this->getMocks();
|
|
|
|
list(, $session, $url, $config, $auth) = $this->getMocks();
|
|
|
|
|
|
|
|
|
|
|
|
$session->expects($this->once())
|
|
|
|
$session->expects($this->atLeastOnce())
|
|
|
|
->method('get')
|
|
|
|
->method('get')
|
|
|
|
->with('errors', [])
|
|
|
|
->willReturnCallback(function ($type) {
|
|
|
|
->willReturn(['foo' => 'bar']);
|
|
|
|
return $type == 'errors' ? ['foo' => 'bar'] : [];
|
|
|
|
|
|
|
|
});
|
|
|
|
$response->expects($this->once())
|
|
|
|
$response->expects($this->once())
|
|
|
|
->method('withView')
|
|
|
|
->method('withView')
|
|
|
|
->with('pages/login')
|
|
|
|
->with('pages/login')
|
|
|
@ -69,6 +72,7 @@ class AuthControllerTest extends TestCase
|
|
|
|
/** @var Validator|MockObject $validator */
|
|
|
|
/** @var Validator|MockObject $validator */
|
|
|
|
$validator = new Validator();
|
|
|
|
$validator = new Validator();
|
|
|
|
$session->set('errors', [['bar' => 'some.bar.error']]);
|
|
|
|
$session->set('errors', [['bar' => 'some.bar.error']]);
|
|
|
|
|
|
|
|
$this->app->instance('session', $session);
|
|
|
|
|
|
|
|
|
|
|
|
$user = new User([
|
|
|
|
$user = new User([
|
|
|
|
'name' => 'foo',
|
|
|
|
'name' => 'foo',
|
|
|
@ -92,8 +96,11 @@ class AuthControllerTest extends TestCase
|
|
|
|
|
|
|
|
|
|
|
|
$response->expects($this->once())
|
|
|
|
$response->expects($this->once())
|
|
|
|
->method('withView')
|
|
|
|
->method('withView')
|
|
|
|
->with('pages/login', ['errors' => collect(['some.bar.error', 'auth.not-found'])])
|
|
|
|
->willReturnCallback(function ($view, $data = []) use ($response) {
|
|
|
|
->willReturn($response);
|
|
|
|
$this->assertEquals('pages/login', $view);
|
|
|
|
|
|
|
|
$this->assertArraySubset(['errors' => collect(['some.bar.error', 'auth.not-found'])], $data);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
|
|
|
});
|
|
|
|
$response->expects($this->once())
|
|
|
|
$response->expects($this->once())
|
|
|
|
->method('redirectTo')
|
|
|
|
->method('redirectTo')
|
|
|
|
->with('news')
|
|
|
|
->with('news')
|
|
|
@ -168,6 +175,8 @@ class AuthControllerTest extends TestCase
|
|
|
|
/** @var Authenticator|MockObject $auth */
|
|
|
|
/** @var Authenticator|MockObject $auth */
|
|
|
|
$auth = $this->createMock(Authenticator::class);
|
|
|
|
$auth = $this->createMock(Authenticator::class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->app->instance('session', $session);
|
|
|
|
|
|
|
|
|
|
|
|
return [$response, $session, $url, $config, $auth];
|
|
|
|
return [$response, $session, $url, $config, $auth];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|