Test Failed
Push — master ( a6b51e...5fffdb )
by Gabriel
08:05
created

TokenFactoryTest::testMake()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
namespace ByTIC\Hello\Tests\Models\Clients\PersonalAccess;
4
5
use ByTIC\Hello\Models\AccessTokens\Token;
6
use ByTIC\Hello\Models\Clients\Client;
7
use ByTIC\Hello\Models\Clients\PersonalAccess\TokenFactory;
8
use ByTIC\Hello\Tests\AbstractTest;
9
use League\OAuth2\Server\AuthorizationServer;
10
use Mockery as m;
11
12
/**
13
 * Class TokenFactoryTest
14
 * @package ByTIC\Hello\Tests\Models\Clients\PersonalAccess
15
 */
16
class TokenFactoryTest extends AbstractTest
17
{
18
    public function testMake()
19
    {
20
        $server = m::mock(AuthorizationServer::class)->makePartial();
21
        $server->shouldReceive('respondToAccessTokenRequest')->andReturn($response = m::mock());
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
22
        $response->shouldReceive('getBody->__toString')->andReturn(json_encode([
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...
23
            'access_token' => 'foo.john.doe',
24
        ]));
25
26
        $client = new Client();
27
28
        $factory = m::mock(TokenFactory::class, [$server, $client])
29
            ->makePartial()->shouldAllowMockingProtectedMethods();
30
        $factory->shouldReceive('findAccessToken')->andReturn(new Token());
31
32
        $token = $factory->make(1, 'token', ['scopes']);
33
        $this->assertInstanceOf(Token::class, $token);
34
    }
35
}
36