Completed
Push — develop ( 9b1d71...66130e )
by Adam
03:07 queued 01:21
created

ApiTest::testPostRaw()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace IBM\Watson\Common\tests\Api;
4
5
use GuzzleHttp\Psr7\Response;
6
use IBM\Watson\Common\stubs\Api;
7
8
class ApiTest extends AbstractTestCase
9
{
10
    public function setup200Response()
11
    {
12
        $this->httpClient->shouldReceive('sendRequest')->once()->andReturnUsing(function () {
13
            return new Response(200, []);
14
        });
15
    }
16
17 View Code Duplication
    public function testGet()
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...
18
    {
19
        $this->setup200Response();
20
21
        $api = new Api($this->httpClient, $this->hydrator, $this->requestBuilder);
22
        $response = $api->getMethod();
23
24
        $this->assertEquals(200, $response->getStatusCode());
25
    }
26
27 View Code Duplication
    public function testPost()
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...
28
    {
29
        $this->setup200Response();
30
31
        $api = new Api($this->httpClient, $this->hydrator, $this->requestBuilder);
32
        $response = $api->postMethod();
33
34
        $this->assertEquals(200, $response->getStatusCode());
35
    }
36
37 View Code Duplication
    public function testPostRaw()
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...
38
    {
39
        $this->setup200Response();
40
41
        $api = new Api($this->httpClient, $this->hydrator, $this->requestBuilder);
42
        $response = $api->postRawMethod();
43
44
        $this->assertEquals(200, $response->getStatusCode());
45
    }
46
47 View Code Duplication
    public function testPut()
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...
48
    {
49
        $this->setup200Response();
50
51
        $api = new Api($this->httpClient, $this->hydrator, $this->requestBuilder);
52
        $response = $api->putMethod();
53
54
        $this->assertEquals(200, $response->getStatusCode());
55
    }
56
57 View Code Duplication
    public function testPatch()
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...
58
    {
59
        $this->setup200Response();
60
61
        $api = new Api($this->httpClient, $this->hydrator, $this->requestBuilder);
62
        $response = $api->patchMethod();
63
64
        $this->assertEquals(200, $response->getStatusCode());
65
    }
66
67 View Code Duplication
    public function testDelete()
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...
68
    {
69
        $this->setup200Response();
70
71
        $api = new Api($this->httpClient, $this->hydrator, $this->requestBuilder);
72
        $response = $api->deleteMethod();
73
74
        $this->assertEquals(200, $response->getStatusCode());
75
    }
76
77
    /**
78
     * @expectedException \IBM\Watson\Common\Exception\Domain\InsufficientPrivilegesException
79
     * @expectedExceptionMessage Not Authorized
80
     */
81
    public function testUnauthorizedExceptionIsThrown()
82
    {
83
        parent::setUpUnauthorizedResponse();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setUpUnauthorizedResponse() instead of testUnauthorizedExceptionIsThrown()). Are you sure this is correct? If so, you might want to change this to $this->setUpUnauthorizedResponse().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
84
85
        $api = new Api($this->httpClient, $this->hydrator, $this->requestBuilder);
86
        $api->getMethod();
87
    }
88
89
    /**
90
     * @expectedException \IBM\Watson\Common\Exception\Domain\NotFoundException
91
     * @expectedExceptionMessage Not Found
92
     */
93
    public function testNotFoundExceptionIsThrown()
94
    {
95
        parent::setUpNotFoundResponse();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setUpNotFoundResponse() instead of testNotFoundExceptionIsThrown()). Are you sure this is correct? If so, you might want to change this to $this->setUpNotFoundResponse().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
96
97
        $api = new Api($this->httpClient, $this->hydrator, $this->requestBuilder);
98
        $api->getMethod();
99
    }
100
101
    /**
102
     * @expectedException \IBM\Watson\Common\Exception\Domain\UnknownErrorException
103
     * @expectedExceptionMessage The service encountered an internal error
104
     */
105
    public function testWatsonUnknownErrorIsThrown()
106
    {
107
        parent::setupWatsonServiceError();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setupWatsonServiceError() instead of testWatsonUnknownErrorIsThrown()). Are you sure this is correct? If so, you might want to change this to $this->setupWatsonServiceError().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
108
109
        $api = new Api($this->httpClient, $this->hydrator, $this->requestBuilder);
110
        $api->getMethod();
111
    }
112
113
    /**
114
     * @expectedException \IBM\Watson\Common\Exception\Domain\UnknownErrorException
115
     * @expectedExceptionMessage The service encountered an internal error
116
     */
117
    public function testDefaultUnknownErrorIsThrown()
118
    {
119
        $this->httpClient->shouldReceive('sendRequest')->once()->andReturnUsing(function () {
120
            return new Response(999, [], '{"error":"The service encountered an internal error"}');
121
        });
122
123
        $api = new Api($this->httpClient, $this->hydrator, $this->requestBuilder);
124
        $api->getMethod();
125
    }
126
}
127