alexdodonov /
mezon-custom-client
| 1 | <?php |
||||
| 2 | namespace Mezon\CustomClient\Tests; |
||||
| 3 | |||||
| 4 | use PHPUnit\Framework\TestCase; |
||||
| 5 | use Mezon\CustomClient\CurlWrapper; |
||||
| 6 | |||||
| 7 | /** |
||||
| 8 | * |
||||
| 9 | * @psalm-suppress PropertyNotSetInConstructor |
||||
| 10 | */ |
||||
| 11 | class CurlWrapperUnitTest extends TestCase |
||||
| 12 | { |
||||
| 13 | |||||
| 14 | /** |
||||
| 15 | * URL for testing purposes |
||||
| 16 | * |
||||
| 17 | * @var string |
||||
| 18 | */ |
||||
| 19 | private $url = 'http://google.com'; |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * Testing GET requests |
||||
| 23 | */ |
||||
| 24 | public function testGetRequest(): void |
||||
| 25 | { |
||||
| 26 | // test body |
||||
| 27 | list ($body, $code) = CurlWrapper::sendRequest($this->url, [], 'GET'); |
||||
| 28 | |||||
| 29 | // assertions |
||||
| 30 | $this->assertStringContainsString('', $body, 'Invalid HTML was returned'); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 31 | $this->assertEquals(301, $code, 'Invalid HTTP code'); |
||||
| 32 | } |
||||
| 33 | |||||
| 34 | /** |
||||
| 35 | * Testing POST requests |
||||
| 36 | */ |
||||
| 37 | public function testPostRequest(): void |
||||
| 38 | { |
||||
| 39 | // test body |
||||
| 40 | list ($body, $code) = CurlWrapper::sendRequest($this->url, [], 'POST', [ |
||||
| 41 | 'data' => 1 |
||||
| 42 | ]); |
||||
| 43 | |||||
| 44 | // assertions |
||||
| 45 | $this->assertStringContainsString('', $body, 'Invalid HTML was returned'); |
||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||
| 46 | $this->assertEquals(405, $code, 'Invalid HTTP code'); |
||||
| 47 | } |
||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * Testing JSON request |
||||
| 51 | */ |
||||
| 52 | public function testJsonRequest(): void |
||||
| 53 | { |
||||
| 54 | // test body |
||||
| 55 | list ($body, $code) = CurlWrapper::sendRequest($this->url, [ |
||||
| 56 | 'Content-type: application/json' |
||||
| 57 | ], 'POST', [ |
||||
| 58 | 'data' => 1 |
||||
| 59 | ]); |
||||
| 60 | $body = json_decode($body, false); |
||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||
| 61 | |||||
| 62 | // assertions |
||||
| 63 | $this->assertEquals(405, $code); |
||||
| 64 | } |
||||
| 65 | } |
||||
| 66 |