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 ( 48a2e9...c23789 )
by Jindřich
20s queued 11s
created

WebServiceTest::testFailCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
1
<?php
2
3
namespace Skaut\Skautis\Test\Unit;
4
5
use Mockery;
6
use Mockery\MockInterface;
7
use PHPUnit\Framework\TestCase;
8
use Psr\EventDispatcher\EventDispatcherInterface;
9
use Skaut\Skautis;
10
use Skaut\Skautis\Exception as SkautisException;
11
use Skaut\Skautis\Wsdl\WebService;
12
use Skaut\Skautis\Wsdl\WebServiceFactory;
13
14
class WebServiceTest extends TestCase
15
{
16
17
    /**
18
     * @var WebServiceFactory
19
     */
20
    private $wsFactory;
21
22
    /**
23
     * @var MockInterface|EventDispatcherInterface
24
     */
25
    private $eventDispatcher;
26
27
    protected function setUp(): void
28
    {
29
        $this->eventDispatcher = Mockery::mock(EventDispatcherInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Mockery::mock(\Psr\Even...atcherInterface::class) of type object<Mockery\LegacyMockInterface> is incompatible with the declared type object<Mockery\MockInter...entDispatcherInterface> of property $eventDispatcher.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30
31
        $this->wsFactory = new WebServiceFactory(
32
          WebService::class,
33
          $this->eventDispatcher
34
        );
35
    }
36
37
    public function testFailCall(): void
38
    {
39
        $data = [
40
          'ID_Application' => 123,
41
          Skautis\User::ID_LOGIN => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
42
        ];
43
        $webService = $this->wsFactory->createWebService(
44
          'https://test-is.skaut.cz/JunakWebservice/UserManagement.asmx?WSDL',
45
          $data
46
        );
47
48
        $preEventCheck = static function ($obj): bool {
49
            return $obj instanceof Skautis\Wsdl\Event\RequestPreEvent;
50
        };
51
52
        $failEventCheck = static function ($obj): bool {
53
            return $obj instanceof Skautis\Wsdl\Event\RequestFailEvent;
54
        };
55
56
        $this->eventDispatcher->expects('dispatch')->withArgs($preEventCheck)->once();
0 ignored issues
show
Bug introduced by
The method expects does only exist in Mockery\MockInterface, but not in Psr\EventDispatcher\EventDispatcherInterface.

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...
57
        $this->eventDispatcher->expects('dispatch')->withArgs($failEventCheck)->once();
58
59
        $this->expectException(SkautisException::class);
60
        $webService->UserDetail();
61
    }
62
}
63