Completed
Push — develop ( 4ff741...64bd10 )
by Tom
14:53
created

ResponseTest::testNoError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Bobbyshaw\WatsonVisualRecognition\Tests\Message;
4
5
use Bobbyshaw\WatsonVisualRecognition\Client;
6
use Bobbyshaw\WatsonVisualRecognition\Message\AbstractRequest;
7
use Bobbyshaw\WatsonVisualRecognition\Message\Response;
8
use Bobbyshaw\WatsonVisualRecognition\Tests\Base;
9
use GuzzleHttp\Client as HttpClient;
10
11
class ResponseTest extends Base
12
{
13
14
    /**
15
     * @var AbstractRequest
16
     */
17
    protected $request;
18
19
    /**
20
     * @var Response
21
     */
22
    protected $response;
23
24
25
    public function setUp()
26
    {
27
        parent::setUp();
28
29
        $data = file_get_contents('Tests/Mock/ErrorResponse.txt');
30
31
        $this->request = $this->getMockForAbstractClass(AbstractRequest::class, [new HttpClient()]);
1 ignored issue
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac... \GuzzleHttp\Client())) of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<Bobbyshaw\WatsonV...essage\AbstractRequest> of property $request.

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...
32
        $this->response = new Response($this->request, $data);
33
    }
34
35
    public function testResponseIsNotSuccessful()
36
    {
37
        $this->assertEquals(false, $this->response->isSuccessful());
38
    }
39
40
    public function testErrorCode()
41
    {
42
        $this->assertEquals(400, $this->response->getErrorCode());
43
    }
44
45
    public function testErrorMessage()
46
    {
47
        $this->assertEquals(
48
            'Upload problem - check that all fields were specified and upload size was less than 100MB',
49
            $this->response->getErrorMessage()
50
        );
51
    }
52
53
    public function testNoError()
54
    {
55
        /** @var \GuzzleHttp\Psr7\Response $response */
56
        $response = $this->getMockHttpResponse('GetClassifiersSuccess.txt');
57
58
        $this->response = new Response($this->request, $response->getBody()->getContents());
59
60
        $this->assertEquals(false, $this->response->getErrorCode());
61
        $this->assertEquals('', $this->response->getErrorMessage());
62
    }
63
64
    /**
65
     * @expectedException \RuntimeException
66
     */
67 View Code Duplication
    public function testInitialisingRequestAfterResponse()
1 ignored issue
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...
68
    {
69
        $container = [];
70
        $guzzle = $this->getMockHttpClientWithHistoryAndResponses(
71
            $container,
72
            [$this->getMockHttpResponse('GetClassifiersSuccess.txt')]
73
        );
74
75
        $client = new Client($guzzle);
76
        $client->initialize(['username' => 'test', 'password' => 'test']);
77
78
        $request = $client->getClassifiers();
79
        $request->send();
80
81
        $request->initialize();
82
    }
83
84
    /**
85
     * @expectedException \RuntimeException
86
     */
87 View Code Duplication
    public function testSetUsernameOnRequestAfterResponse()
1 ignored issue
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...
88
    {
89
        $container = [];
90
        $guzzle = $this->getMockHttpClientWithHistoryAndResponses(
91
            $container,
92
            [$this->getMockHttpResponse('GetClassifiersSuccess.txt')]
93
        );
94
95
        $client = new Client($guzzle);
96
        $client->initialize(['username' => 'test', 'password' => 'test']);
97
98
        $request = $client->getClassifiers();
99
        $request->send();
100
101
        $request->setUsername('test2');
102
    }
103
}
104