Passed
Push — master ( 0e941b...0f3de7 )
by Conrad
08:36
created

tests/ScopeTest.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace AdvancedLearning\Oauth2Server\Tests;
4
5
use AdvancedLearning\Oauth2Server\Extensions\GroupExtension;
6
use AdvancedLearning\Oauth2Server\Services\ScopeService;
7
use SilverStripe\Core\Config\Config;
8
use SilverStripe\Dev\SapphireTest;
9
use SilverStripe\Security\Group;
10
use SilverStripe\Security\Member;
11
12
class ScopeTest extends SapphireTest
13
{
14
    protected static $fixture_file = './OauthFixture.yml';
15
16
    /**
17
     * Setup test environment.
18
     */
19
    public function setUp()
20
    {
21
        // add GroupExtension for scopes
22
        Config::forClass(Group::class)->merge('extensions', [GroupExtension::class]);
23
24
        parent::setUp();
25
    }
26
27 View Code Duplication
    public function testHasScope()
0 ignored issues
show
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...
28
    {
29
        $service = new ScopeService();
30
        $member = $this->objFromFixture(Member::class, 'member1');
31
32
        $this->assertTrue($service->hasScope('scope1', $member, 'Member should have scope1'));
0 ignored issues
show
$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...
The call to ScopeService::hasScope() has too many arguments starting with 'Member should have scope1'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
33
        $this->assertFalse($service->hasScope('scope2', $member, 'Member should have scope2'));
0 ignored issues
show
$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...
The call to ScopeService::hasScope() has too many arguments starting with 'Member should have scope2'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
34
    }
35
}