43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use ReflectionClass;
|
|
use Services\Auth;
|
|
use Services\Auth\FileAuthDriver;
|
|
use System\Classes\MyException;
|
|
|
|
class AuthTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
// Сбрасываем кэш инстансов драйверов, чтобы тесты не влияли друг на друга.
|
|
$ref = new ReflectionClass(Auth::class);
|
|
$prop = $ref->getProperty('_instances');
|
|
$prop->setAccessible(true);
|
|
$prop->setValue(null, []);
|
|
}
|
|
|
|
public function testDefaultDriverIsFile(): void
|
|
{
|
|
$this->assertInstanceOf(FileAuthDriver::class, Auth::instance());
|
|
}
|
|
|
|
public function testExplicitFileDriver(): void
|
|
{
|
|
$this->assertInstanceOf(FileAuthDriver::class, Auth::instance('file'));
|
|
}
|
|
|
|
public function testInstanceIsCachedPerDriver(): void
|
|
{
|
|
$this->assertSame(Auth::instance('file'), Auth::instance('file'));
|
|
}
|
|
|
|
public function testUnknownDriverThrows(): void
|
|
{
|
|
$this->expectException(MyException::class);
|
|
Auth::instance('ldap');
|
|
}
|
|
}
|