Completed
Push — master ( 882aff...f627fa )
by Alex
02:58
created

CurlWrapperUnitTest::testJsonRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Mezon\CustomClient\Tests;
3
4
use PHPUnit\Framework\TestCase;
5
use Mezon\CustomClient\CurlWrapper;
6
7
class CurlWrapperUnitTest extends TestCase
8
{
9
10
    /**
11
     * URL for testing purposes
12
     *
13
     * @var string
14
     */
15
    private $url = 'http://google.com';
16
17
    /**
18
     * Testing GET requests
19
     */
20
    public function testGetRequest()
21
    {
22
        // test body
23
        list ($body, $code) = CurlWrapper::sendRequest($this->url, [], 'GET');
24
25
        // assertions
26
        $this->assertStringContainsString('', $body, 'Invalid HTML was returned');
0 ignored issues
show
Bug introduced by
It seems like $body can also be of type true; however, parameter $haystack of PHPUnit\Framework\Assert...tStringContainsString() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        $this->assertStringContainsString('', /** @scrutinizer ignore-type */ $body, 'Invalid HTML was returned');
Loading history...
27
        $this->assertEquals(301, $code, 'Invalid HTTP code');
28
    }
29
30
    /**
31
     * Testing POST requests
32
     */
33
    public function testPostRequest()
34
    {
35
        // test body
36
        list ($body, $code) = CurlWrapper::sendRequest($this->url, [], 'POST', [
37
            'data' => 1
38
        ]);
39
40
        // assertions
41
        $this->assertStringContainsString('', $body, 'Invalid HTML was returned');
0 ignored issues
show
Bug introduced by
It seems like $body can also be of type true; however, parameter $haystack of PHPUnit\Framework\Assert...tStringContainsString() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        $this->assertStringContainsString('', /** @scrutinizer ignore-type */ $body, 'Invalid HTML was returned');
Loading history...
42
        $this->assertEquals(405, $code, 'Invalid HTTP code');
43
    }
44
45
    /**
46
     * Testing JSON request
47
     */
48
    public function testJsonRequest(): void
49
    {
50
        // test body
51
        list ($body, $code) = CurlWrapper::sendRequest($this->url, [
52
            'Content-type: application/json'
53
        ], 'POST', [
54
            'data' => 1
55
        ]);
56
        $body = json_decode($body, false);
0 ignored issues
show
Bug introduced by
It seems like $body can also be of type true; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        $body = json_decode(/** @scrutinizer ignore-type */ $body, false);
Loading history...
Unused Code introduced by
The assignment to $body is dead and can be removed.
Loading history...
57
58
        // assertions
59
        $this->assertEquals(405, $code);
60
    }
61
}
62