|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Files\Authorization; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Files\Databases\Queries\FileCategoryAuthLoader as AuthLoader; |
|
8
|
|
|
use Casbin\Exceptions\CasbinException; |
|
9
|
|
|
use Casbin\Model\Model; |
|
10
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
class FileCategoryProviderTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var FileCategoryProvider */ |
|
16
|
|
|
protected $sut; |
|
17
|
|
|
|
|
18
|
|
|
/** @var AuthLoader|MockObject */ |
|
19
|
|
|
protected $authLoaderMock; |
|
20
|
|
|
|
|
21
|
|
|
public function setUp(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$this->authLoaderMock = $this->createMock(AuthLoader::class); |
|
24
|
|
|
|
|
25
|
|
|
$this->sut = new FileCategoryProvider($this->authLoaderMock); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testSavePolicyReturnsTrue() |
|
29
|
|
|
{ |
|
30
|
|
|
$modelStub = $this->createMock(Model::class); |
|
31
|
|
|
|
|
32
|
|
|
$actualResult = $this->sut->savePolicy($modelStub); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertTrue($actualResult); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testAddPolicyDoesNotThrowException() |
|
38
|
|
|
{ |
|
39
|
|
|
$actualResult = $this->sut->addPolicy('foo', 'bar', []); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
$this->assertNull($actualResult); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testRemovePolicyReturnZero() |
|
45
|
|
|
{ |
|
46
|
|
|
$actualResult = $this->sut->removePolicy('foo', 'bar', []); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertSame(0, $actualResult); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testRemoveFilterPolicyThrowsCasbinException() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->expectException(CasbinException::class); |
|
54
|
|
|
|
|
55
|
|
|
$this->sut->removeFilteredPolicy('foo', 'bar', 'baz'); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.