GroupScopesTest::testServiceScopes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: conrad
5
 * Date: 21/05/18
6
 * Time: 4:10 PM
7
 */
8
9
namespace AdvancedLearning\Oauth2Server\Tests;
10
11
12
use AdvancedLearning\Oauth2Server\Entities\UserEntity;
13
use AdvancedLearning\Oauth2Server\Extensions\GroupExtension;
14
use AdvancedLearning\Oauth2Server\Services\ScopeService;
15
use SilverStripe\Core\Config\Config;
16
use SilverStripe\Dev\SapphireTest;
17
use SilverStripe\Security\Group;
18
use SilverStripe\Security\Member;
19
20
class GroupScopesTest extends SapphireTest
21
{
22
    protected static $fixture_file = 'tests/OAuthFixture.yml';
23
24
    public function setUp()
25
    {
26
        // add GroupExtension for scopes
27
        Config::forClass(Group::class)->merge('extensions', [GroupExtension::class]);
28
29
        return parent::setUp(); // TODO: Change the autogenerated stub
30
    }
31
32 View Code Duplication
    public function testServiceScopes()
0 ignored issues
show
Duplication introduced by Conrad Dobbs
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        $obj = $this->objFromFixture(Member::class, 'member1');
35
36
        $service = new ScopeService();
37
38
        $this->assertTrue($service->hasScope('scope1', $obj), 'Member should have the scope via groups');
0 ignored issues
show
Documentation introduced by Conrad Dobbs
$obj is of type object<SilverStripe\ORM\DataObject>|null, but the function expects a object<SilverStripe\Security\Member>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
        $this->assertFalse($service->hasScope('scope2', $obj), 'Member should not have scope2');
0 ignored issues
show
Documentation introduced by Conrad Dobbs
$obj is of type object<SilverStripe\ORM\DataObject>|null, but the function expects a object<SilverStripe\Security\Member>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
40
    }
41
42 View Code Duplication
    public function testEntityScopes()
0 ignored issues
show
Duplication introduced by Conrad Dobbs
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        $member = $this->objFromFixture(Member::class, 'member1');
45
46
        $entity = new UserEntity($member);
0 ignored issues
show
Documentation introduced by Conrad Dobbs
$member is of type object<SilverStripe\ORM\DataObject>|null, but the function expects a object<SilverStripe\Security\Member>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
48
        $this->assertTrue($entity->hasScope('scope1'), 'Member should have scope1');
49
        $this->assertFalse($entity->hasScope('scope2'), 'Member should not have scope2');
50
    }
51
52
}