HttpMockedTestCase::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Bowerphp\Test;
4
5
use Mockery;
6
7
abstract class HttpMockedTestCase extends BowerphpTestCase
8
{
9
    protected $httpClient;
10
11
    protected $request;
12
13
    protected $response;
14
15
    protected $config;
16
17
    protected function setUp()
18
    {
19
        parent::setUp();
20
        $this->httpClient = Mockery::mock('Github\HttpClient\HttpClientInterface');
21
        $this->response = Mockery::mock('Guzzle\Http\Message\Response');
22
        $this->config = Mockery::mock('Bowerphp\Config\ConfigInterface');
23
24
        $this->config
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...
25
            ->shouldReceive('getOverridesSection')->andReturn([])
26
            ->shouldReceive('getOverrideFor')->andReturn([])
27
            ->shouldReceive('getBasePackagesUrl')->andReturn('http://bower.herokuapp.com/packages/')
28
        ;
29
    }
30
31
    protected function prepareRequest($query, $packageJson)
32
    {
33
        $this->httpClient
34
            ->shouldReceive('get')->with('http://bower.herokuapp.com/packages/' . $query)->andReturn($this->response)
35
        ;
36
        $this->response
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...
37
            ->shouldReceive('getBody')->andReturn($packageJson)
38
        ;
39
    }
40
}
41