GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 3.x ( 52ff30...48a2e9 )
by Jindřich
12s queued 11s
created

SkautisTest::testSingletonTestMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Skaut\Skautis\Test\Unit;
4
5
use PHPUnit\Framework\TestCase;
6
use Skaut\Skautis\Config;
7
use Skaut\Skautis\DynamicPropertiesDisabledException;
8
use Skaut\Skautis\Skautis;
9
use Skaut\Skautis\User;
10
use Skaut\Skautis\Wsdl\WebServiceName;
11
use Skaut\Skautis\Wsdl\WsdlManager;
12
13
class SkautisTest extends TestCase
14
{
15
16
    protected function tearDown(): void
17
    {
18
      \Mockery::close();
19
    }
20
21
    public function testSingletonSameId(): void
22
    {
23
        $skautis = Skautis::getInstance('asd');
24
        $skautisA = Skautis::getInstance('asd');
25
        $this->assertSame($skautis, $skautisA);
26
    }
27
28
    public function testSingletonDifferentId(): void
29
    {
30
        $skautis = Skautis::getInstance('asd');
31
        $skautisA = Skautis::getInstance('qwe');
32
        $this->assertNotSame($skautis, $skautisA);
33
    }
34
35
    public function testSingletonTestMode(): void
36
    {
37
        $appId = 'some-app-id';
38
39
        $skautisWithTestMode = Skautis::getInstance($appId, Config::TEST_MODE_ENABLED);
40
        $skautisWithoutTestMode = Skautis::getInstance($appId, Config::TEST_MODE_DISABLED);
41
42
        $this->assertNotSame($skautisWithTestMode, $skautisWithoutTestMode);
43
    }
44
45
    public function testGettingService(): void {
46
      $skautis = Skautis::getInstance('asd');
47
48
      $serviceA = $skautis->UserManagement;
49
      $serviceB = $skautis->getWebService(WebServiceName::USER_MANAGEMENT);
50
51
      $this->assertSame($serviceA, $serviceB);
52
    }
53
54
    public function testGettingServiceUsingAlias(): void {
55
      $skautis = Skautis::getInstance('asd');
56
57
      $serviceA = $skautis->UserManagement;
58
      $serviceB = $skautis->user;
0 ignored issues
show
Documentation introduced by
The property $user is declared private in Skaut\Skautis\Skautis. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
59
      $serviceC = $skautis->usr;
0 ignored issues
show
Documentation introduced by
The property usr does not exist on object<Skaut\Skautis\Skautis>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
60
61
      $this->assertSame($serviceA, $serviceB);
62
      $this->assertSame($serviceB, $serviceC);
63
    }
64
65
    public function testSettingWebService(): void {
66
      $skautis = Skautis::getInstance('asd');
67
68
      $this->expectException(DynamicPropertiesDisabledException::class);
69
      $skautis->UserManagement = 'asd';
70
    }
71
72
    public function testGetLoginURL(): void {
73
      $skautis = Skautis::getInstance('asd');
74
      $urlEncodedAddress = 'https://is.skaut.cz/Login/?appid=asd&ReturnUrl=https%3A%2F%2Fmy-web.nowhere%2Fasd';
75
      $this->assertEquals($urlEncodedAddress, $skautis->getLoginUrl('https://my-web.nowhere/asd'));
76
    }
77
78
79
    public function testGetLogoutURL(): void {
80
81
      /** @var User $user */
82
      $user = \Mockery::mock(User::class);
83
      $user->shouldReceive('getLoginId')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Skaut\Skautis\User>.

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...
84
        ->once()
85
        ->andReturn('log://123out');
86
87
      /** @var WsdlManager $wsdlManager */
88
      $config = new Config('asd');
89
      $wsdlManager = \Mockery::mock(WsdlManager::class);
90
      $wsdlManager->shouldReceive('getConfig')
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
91
        ->andReturn($config);
92
93
      $skautis = new Skautis($wsdlManager, $user);
0 ignored issues
show
Documentation introduced by
$wsdlManager is of type object<Mockery\LegacyMockInterface>, but the function expects a object<Skaut\Skautis\Wsdl\WsdlManager>.

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...
94
95
      $urlEncodedAddress = 'https://test-is.skaut.cz/Login/LogOut.aspx?appid=asd&token=log%3A%2F%2F123out';
96
      $this->assertEquals($urlEncodedAddress, $skautis->getLogoutUrl());
97
    }
98
99
    public function testGetRegisterURL(): void {
100
      $skautis = Skautis::getInstance('asd');
101
      $urlEncodedAddress = 'https://is.skaut.cz/Login/Registration.aspx?appid=asd';
102
      $this->assertEquals($urlEncodedAddress, $skautis->getRegisterUrl());
103
    }
104
105
    public function testEventSetter(): void
106
    {
107
      $this->markTestSkipped();
108
        //@TODO
109
    }
110
}
111