2018-10-08 19:30:37 +02:00
|
|
|
<?php
|
|
|
|
|
2023-02-03 20:41:59 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-10-08 19:30:37 +02:00
|
|
|
namespace Engelsystem\Test\Unit\Helpers;
|
|
|
|
|
|
|
|
use Engelsystem\Application;
|
2018-11-27 12:01:36 +01:00
|
|
|
use Engelsystem\Config\Config;
|
2018-10-08 19:30:37 +02:00
|
|
|
use Engelsystem\Helpers\Authenticator;
|
|
|
|
use Engelsystem\Helpers\AuthenticatorServiceProvider;
|
2018-10-11 01:26:34 +02:00
|
|
|
use Engelsystem\Http\Request;
|
2018-10-08 19:30:37 +02:00
|
|
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
2018-10-11 01:26:34 +02:00
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
2018-10-08 19:30:37 +02:00
|
|
|
|
|
|
|
class AuthenticatorServiceProviderTest extends ServiceProviderTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Helpers\AuthenticatorServiceProvider::register()
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testRegister(): void
|
2018-10-08 19:30:37 +02:00
|
|
|
{
|
|
|
|
$app = new Application();
|
2018-10-11 01:26:34 +02:00
|
|
|
$app->bind(ServerRequestInterface::class, Request::class);
|
2018-10-08 19:30:37 +02:00
|
|
|
|
2022-11-06 12:41:52 +01:00
|
|
|
$config = new Config([
|
|
|
|
'password_algorithm' => PASSWORD_DEFAULT,
|
|
|
|
'auth_guest_role' => 42,
|
|
|
|
'auth_default_role' => 1337,
|
|
|
|
]);
|
2018-11-27 12:01:36 +01:00
|
|
|
$app->instance('config', $config);
|
|
|
|
|
2018-10-08 19:30:37 +02:00
|
|
|
$serviceProvider = new AuthenticatorServiceProvider($app);
|
|
|
|
$serviceProvider->register();
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Authenticator::class, $app->get(Authenticator::class));
|
|
|
|
$this->assertInstanceOf(Authenticator::class, $app->get('authenticator'));
|
2018-11-14 02:17:27 +01:00
|
|
|
$this->assertInstanceOf(Authenticator::class, $app->get('auth'));
|
2018-11-27 12:01:36 +01:00
|
|
|
|
|
|
|
/** @var Authenticator $auth */
|
|
|
|
$auth = $app->get(Authenticator::class);
|
|
|
|
$this->assertEquals(PASSWORD_DEFAULT, $auth->getPasswordAlgorithm());
|
2019-07-28 15:33:01 +02:00
|
|
|
$this->assertEquals(42, $auth->getGuestRole());
|
2022-11-06 12:41:52 +01:00
|
|
|
$this->assertEquals(1337, $auth->getDefaultRole());
|
2018-10-08 19:30:37 +02:00
|
|
|
}
|
|
|
|
}
|