Test Failed
Push — master ( 78007a...35605b )
by Elijah
02:39
created

UserTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testFalseHasRole() 0 8 1
A createMockRole() 0 3 1
A getUser() 0 3 1
A testTrueHasRole() 0 10 1
1
<?php
2
3
/*
4
 * This file is part of the EloyekunlePermissionsBundle package.
5
 *
6
 * (c) Elijah Oyekunle <https://elijahoyekunle.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Eloyekunle\PermissionsBundle\Tests\Model;
13
14
use Eloyekunle\PermissionsBundle\Model\RoleInterface;
15
use Eloyekunle\PermissionsBundle\Model\UserInterface;
16
use Eloyekunle\PermissionsBundle\Tests\TestRole;
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
19
class UserTest extends TestCase
20
{
21
    public function testTrueHasRole()
22
    {
23
        $user = $this->getUser();
24
        $newrole = $this->createMockRole('ROLE_X');
25
26
        $user->addRole($newrole);
27
        $this->assertTrue($user->hasRole($newrole));
28
29
        $user->removeRole($newrole);
30
        $this->assertFalse($user->hasRole($newrole));
31
    }
32
33
    public function testFalseHasRole()
34
    {
35
        $user = $this->getUser();
36
        $newrole = $this->createMockRole('ROLE_X');
37
38
        $this->assertFalse($user->hasRole($newrole));
39
        $user->addRole($newrole);
40
        $this->assertTrue($user->hasRole($newrole));
41
    }
42
43
    /**
44
     * @param $roleName
45
     *
46
     * @return RoleInterface
47
     */
48
    protected function createMockRole($roleName)
49
    {
50
        return new TestRole($roleName);
51
    }
52
53
    /**
54
     * @return UserInterface
55
     *
56
     * @throws \ReflectionException
57
     */
58
    protected function getUser()
59
    {
60
        return $this->getMockForAbstractClass('Eloyekunle\PermissionsBundle\Model\User');
61
    }
62
}
63