Completed
Push — develop ( bc21b0...0bdfd4 )
by Adam
24:26 queued 09:29
created

src/Common/tests/RequestBuilderTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace IBM\Watson\Common\tests;
4
5
use GuzzleHttp\Psr7\Request;
6
use GuzzleHttp\Psr7\Stream;
7
use Http\Discovery\MessageFactoryDiscovery;
8
use Http\Discovery\StreamFactoryDiscovery;
9
use Http\Message\MultipartStream\MultipartStreamBuilder;
10
use Http\Message\RequestFactory;
11
use Http\Message\StreamFactory;
12
use IBM\Watson\Common\RequestBuilder;
13
use PHPUnit\Framework\TestCase;
14
use Mockery as m;
15
use Psr\Http\Message\RequestInterface;
16
use Psr\Http\Message\StreamInterface;
17
18
class RequestBuilderTest extends TestCase
19
{
20
    private $requestFactory;
21
    private $multipartStreamBuilder;
22
23
    public function setUp()
24
    {
25
        $this->requestFactory = MessageFactoryDiscovery::find();
26
        $streamFactory = StreamFactoryDiscovery::find();
27
        $this->multipartStreamBuilder = m::mock(MultipartStreamBuilder::class, [$streamFactory])->makePartial();
28
    }
29
30
    public function testCreate()
31
    {
32
        $requestBuilder = new RequestBuilder($this->requestFactory, $this->multipartStreamBuilder);
0 ignored issues
show
$this->multipartStreamBuilder is of type object<Mockery\Mock>, but the function expects a null|object<Http\Message...MultipartStreamBuilder>.

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...
33
34
        $this->assertInstanceOf(RequestInterface::class, $requestBuilder->create('GET', '/something', []));
35
    }
36
37
    public function testCreateMultipartStream()
38
    {
39
        $requestBuilder = new RequestBuilder($this->requestFactory, $this->multipartStreamBuilder);
0 ignored issues
show
$this->multipartStreamBuilder is of type object<Mockery\Mock>, but the function expects a null|object<Http\Message...MultipartStreamBuilder>.

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...
40
41
        $params = [
42
            [
43
                'name' => 'somename',
44
                'content' => 'content'
45
            ]
46
        ];
47
48
        $this->assertInstanceOf(RequestInterface::class, $requestBuilder->create('GET', '/something', [], $params));
49
    }
50
}
51