|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AbterPhp\Framework\Bootstrappers\Authorization; |
|
4
|
|
|
|
|
5
|
|
|
use AbterPhp\Framework\Authorization\CombinedAdapter; |
|
6
|
|
|
use AbterPhp\Framework\Constant\Env; |
|
7
|
|
|
use AbterPhp\Framework\Environments\Environment; |
|
8
|
|
|
use Casbin\Enforcer; |
|
9
|
|
|
use Opulence\Ioc\Container; |
|
10
|
|
|
use Opulence\Sessions\ISession; |
|
11
|
|
|
use Opulence\Views\Compilers\Fortune\ITranspiler; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
class EnforcerBootstrapperTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var EnforcerBootstrapper */ |
|
17
|
|
|
protected EnforcerBootstrapper $sut; |
|
18
|
|
|
|
|
19
|
|
|
public function setUp(): void |
|
20
|
|
|
{ |
|
21
|
|
|
$this->sut = new EnforcerBootstrapper(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
protected function tearDown(): void |
|
25
|
|
|
{ |
|
26
|
|
|
Environment::unsetVar(Env::DIR_AUTH_CONFIG); |
|
27
|
|
|
Environment::unsetVar(Env::ENV_NAME); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testRegisterBindingsWithoutSession() |
|
31
|
|
|
{ |
|
32
|
|
|
Environment::setVar(Env::DIR_AUTH_CONFIG, '/tmp'); |
|
33
|
|
|
Environment::setVar(Env::ENV_NAME, 'foo'); |
|
34
|
|
|
|
|
35
|
|
|
file_put_contents('/tmp/model.conf', ''); |
|
36
|
|
|
|
|
37
|
|
|
$mockAdapter = $this->getMockBuilder(CombinedAdapter::class)->disableOriginalConstructor()->getMock(); |
|
38
|
|
|
|
|
39
|
|
|
$container = new Container(); |
|
40
|
|
|
$container->bindInstance(CombinedAdapter::class, $mockAdapter); |
|
41
|
|
|
|
|
42
|
|
|
$this->sut->registerBindings($container); |
|
43
|
|
|
|
|
44
|
|
|
$actual = $container->resolve(Enforcer::class); |
|
45
|
|
|
$this->assertInstanceOf(Enforcer::class, $actual); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testRegisterBindingsWithSession() |
|
49
|
|
|
{ |
|
50
|
|
|
Environment::setVar(Env::DIR_AUTH_CONFIG, '/tmp'); |
|
51
|
|
|
Environment::setVar(Env::ENV_NAME, 'foo'); |
|
52
|
|
|
|
|
53
|
|
|
file_put_contents('/tmp/model.conf', ''); |
|
54
|
|
|
|
|
55
|
|
|
$mockAdapter = $this->getMockBuilder(CombinedAdapter::class)->disableOriginalConstructor()->getMock(); |
|
56
|
|
|
$sessionMock = $this->getMockBuilder(ISession::class)->getMock(); |
|
57
|
|
|
$mockTranspiler = $this->getMockBuilder(ITranspiler::class)->getMock(); |
|
58
|
|
|
|
|
59
|
|
|
$container = new Container(); |
|
60
|
|
|
$container->bindInstance(CombinedAdapter::class, $mockAdapter); |
|
61
|
|
|
$container->bindInstance(ISession::class, $sessionMock); |
|
62
|
|
|
$container->bindInstance(ITranspiler::class, $mockTranspiler); |
|
63
|
|
|
|
|
64
|
|
|
$this->sut->registerBindings($container); |
|
65
|
|
|
|
|
66
|
|
|
$actual = $container->resolve(Enforcer::class); |
|
67
|
|
|
$this->assertInstanceOf(Enforcer::class, $actual); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|