Completed
Push — master ( e9d211...82b216 )
by Craig
05:41
created

AbstractPermissionTestCase   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
c 1
b 0
f 0
dl 0
loc 65
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 33 3
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;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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')
0 ignored issues
show
Bug introduced by
The method method() does not exist on Zikula\UsersModule\Entity\UserEntity. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
                    ->/** @scrutinizer ignore-call */ 
87
                      method('getGroups')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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