|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Zikula package. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Zikula\PermissionsModule\Tests\Api; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
18
|
|
|
use Symfony\Component\Translation\IdentityTranslator; |
|
19
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
|
20
|
|
|
use Zikula\GroupsModule\Constant as GroupsConstant; |
|
21
|
|
|
use Zikula\PermissionsModule\Entity\RepositoryInterface\PermissionRepositoryInterface; |
|
22
|
|
|
use Zikula\PermissionsModule\Tests\Api\Fixtures\StubPermissionRepository; |
|
23
|
|
|
use Zikula\UsersModule\Api\ApiInterface\CurrentUserApiInterface; |
|
24
|
|
|
use Zikula\UsersModule\Constant; |
|
25
|
|
|
use Zikula\UsersModule\Entity\RepositoryInterface\UserRepositoryInterface; |
|
26
|
|
|
use Zikula\UsersModule\Entity\UserEntity; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @ |
|
30
|
|
|
*/ |
|
31
|
|
|
class AbstractPermissionTestCase extends TestCase |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* for testing purposes only. |
|
35
|
|
|
*/ |
|
36
|
|
|
public const RANDOM_USER_ID = 99; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var PermissionRepositoryInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $permRepo; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var UserEntity |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $user; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var UserRepositoryInterface |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $userRepo; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var CurrentUserApiInterface |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $currentUserApi; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var TranslatorInterface |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $translator; |
|
62
|
|
|
|
|
63
|
|
|
protected function setUp(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->permRepo = new StubPermissionRepository(); |
|
66
|
|
|
$this->user = $this |
|
67
|
|
|
->getMockBuilder(UserEntity::class) |
|
68
|
|
|
->disableOriginalConstructor() |
|
69
|
|
|
->getMock(); |
|
70
|
|
|
$this->userRepo = $this |
|
71
|
|
|
->getMockBuilder(UserRepositoryInterface::class) |
|
72
|
|
|
->disableOriginalConstructor() |
|
73
|
|
|
->getMock(); |
|
74
|
|
|
$this->userRepo |
|
75
|
|
|
->method('findByUids') |
|
76
|
|
|
->with($this->anything()) |
|
77
|
|
|
->willReturnCallback(function (array $uids) { |
|
78
|
|
|
$groups = new ArrayCollection(); |
|
79
|
|
|
// getGroups returns [gid => $group, gid => $group, ...] |
|
80
|
|
|
if (in_array(self::RANDOM_USER_ID, $uids, true)) { |
|
81
|
|
|
$groups = new ArrayCollection([GroupsConstant::GROUP_ID_USERS => []]); |
|
82
|
|
|
} elseif (in_array(Constant::USER_ID_ADMIN, $uids, true)) { |
|
83
|
|
|
$groups = new ArrayCollection([GroupsConstant::GROUP_ID_USERS => [], GroupsConstant::GROUP_ID_ADMIN => []]); |
|
84
|
|
|
} |
|
85
|
|
|
$this->user |
|
86
|
|
|
->method('getGroups') |
|
|
|
|
|
|
87
|
|
|
->willReturn($groups); |
|
88
|
|
|
|
|
89
|
|
|
return [$this->user]; // must return an array of users. |
|
90
|
|
|
}); |
|
91
|
|
|
$this->currentUserApi = $this |
|
92
|
|
|
->getMockBuilder(CurrentUserApiInterface::class) |
|
93
|
|
|
->disableOriginalConstructor() |
|
94
|
|
|
->getMock(); |
|
95
|
|
|
$this->translator = new IdentityTranslator(); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths