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 ( 542ce3...d805b4 )
by Jindřich
03:23 queued 02:10
created

SkautisTest::testGetLogoutURL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Test\Skautis;
4
5
use PHPUnit_Framework_TestCase;
6
use Skautis\Config;
7
use Skautis\DynamicPropertiesDisabledException;
8
use Skautis\Skautis;
9
use Skautis\User;
10
use Skautis\Wsdl\WebServiceName;
11
use Skautis\Wsdl\WsdlManager;
12
13
class SkautisTest extends PHPUnit_Framework_TestCase
14
{
15
16
    protected function tearDown()
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 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<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<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')
91
        ->andReturn($config);
92
93
      $skautis = new Skautis($wsdlManager, $user);
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
        //@TODO
108
    }
109
}
110