Completed
Push — develop ( 68a985...a1f82e )
by Adam
10s
created

ArrayHydratorTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace IBM\Watson\Common\tests;
4
5
use GuzzleHttp\Psr7\Response;
6
use IBM\Watson\Common\Hydrator\ArrayHydrator;
7
use PHPUnit\Framework\TestCase;
8
use Mockery as m;
9
10
class ArrayHydratorTest extends TestCase
11
{
12
    private $response;
13
    private $hydrator;
14
15
    public function setUp()
16
    {
17
        $this->response = m::mock(Response::class);
18
19
        $this->hydrator = new ArrayHydrator();
20
    }
21
22
    public function testSuccessfulHydration()
23
    {
24
        $response = m::mock(Response::class, [
25
            200,
26
            ['Content-Type' => 'application/json'],
27
            '{"document_tone": {}}'
28
        ])->makePartial();
29
30
31
        $result = $this->hydrator->hydrate($response);
0 ignored issues
show
Documentation introduced by
$response is of type object<Mockery\Mock>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

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...
32
33
        $this->assertArrayHasKey('document_tone', $result);
34
    }
35
36
    /**
37
     * @expectedException \IBM\Watson\Common\Exception\HydrationException
38
     * @expectedExceptionMessage The ArrayHydrator cannot hydrate response with Content-Type: text/plain
39
     */
40
    public function testHydrateFailsForNoneJsonResponses()
41
    {
42
        $response = m::mock(Response::class, [200, ['Content-Type' => 'text/plain']])->makePartial();
43
44
        $this->hydrator->hydrate($response);
0 ignored issues
show
Documentation introduced by
$response is of type object<Mockery\Mock>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

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...
45
    }
46
47
    /**
48
     * @expectedException \IBM\Watson\Common\Exception\HydrationException
49
     */
50 View Code Duplication
    public function testHydrateFailsWhenJsonDecodeFails()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        $response = m::mock(Response::class, [200, ['Content-Type' => 'application/json'], '{"brokenJson}'])
53
            ->makePartial();
54
55
        $this->hydrator->hydrate($response);
0 ignored issues
show
Documentation introduced by
$response is of type object<Mockery\Mock>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

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...
56
    }
57
}
58