-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimpleRequestTest.php
More file actions
52 lines (42 loc) · 1.71 KB
/
Copy pathSimpleRequestTest.php
File metadata and controls
52 lines (42 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Jetimob\Http\Tests\Feature;
use Jetimob\Http\Facades\Http;
use Jetimob\Http\Request;
use Jetimob\Http\Tests\TestCase;
use Jetimob\Http\Tests\Unit\DummyData\JsonPlaceholderAddress;
use Jetimob\Http\Tests\Unit\DummyData\JsonPlaceholderAddressGeo;
use Jetimob\Http\Tests\Unit\DummyData\JsonPlaceholderUser;
use Jetimob\Http\Tests\Unit\DummyData\JsonPlaceholderUsersResponse;
class SimpleRequestTest extends TestCase
{
/** @test */
public function simpleResponseExpected(): void
{
$response = Http::send(new Request('GET', 'http://google.com'));
self::assertNotEmpty($response);
}
/** @test */
public function complexResponseWithArrayTyping(): void
{
/** @var JsonPlaceholderUsersResponse $response */
$response = Http::sendExpectingResponseClass(
new Request('get', 'https://jsonplaceholder.typicode.com/users'),
JsonPlaceholderUsersResponse::class,
);
self::assertNotEmpty($response);
self::assertInstanceOf(JsonPlaceholderUsersResponse::class, $response);
$container = $response->getContainer();
self::assertNotEmpty($container);
$user = $container[0];
self::assertNotEmpty($user);
self::assertInstanceOf(JsonPlaceholderUser::class, $user);
$address = $user->getAddress();
self::assertNotEmpty($address);
self::assertInstanceOf(JsonPlaceholderAddress::class, $address);
$geoLocation = $address->getGeo();
self::assertNotEmpty($geoLocation);
self::assertInstanceOf(JsonPlaceholderAddressGeo::class, $geoLocation);
self::assertNotEmpty($geoLocation->getLat());
self::assertNotEmpty($geoLocation->getLng());
}
}