/
EndpointTest.php
134 lines (110 loc) · 5.55 KB
/
EndpointTest.php
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
namespace Laravie\Codex\TestCase;
use GuzzleHttp\Psr7\Uri;
use Laravie\Codex\Endpoint;
use PHPUnit\Framework\TestCase;
class EndpointTest extends TestCase
{
/** @test */
public function it_can_build_basic_endpoint()
{
$endpoint = new Endpoint('https://laravel.com', 'docs');
$this->assertSame('https', $endpoint->getScheme());
$this->assertSame('laravel.com', $endpoint->getHost());
$this->assertSame('https://laravel.com', $endpoint->getUri());
$this->assertSame(['docs'], $endpoint->getPath());
$this->assertSame([], $endpoint->getQuery());
$this->assertInstanceOf('GuzzleHttp\Psr7\Uri', $endpoint->get());
$this->assertSame('https://laravel.com/docs', (string) $endpoint->get());
$this->assertSame('https://laravel.com/docs', (string) $endpoint);
}
/** @test */
public function it_can_build_basic_endpoint_with_tailing_slash()
{
$endpoint = new Endpoint('https://laravel.com/', 'docs');
$this->assertSame('https', $endpoint->getScheme());
$this->assertSame('laravel.com', $endpoint->getHost());
$this->assertSame('https://laravel.com', $endpoint->getUri());
$this->assertSame(['docs'], $endpoint->getPath());
$this->assertSame([], $endpoint->getQuery());
$this->assertInstanceOf('GuzzleHttp\Psr7\Uri', $endpoint->get());
$this->assertSame('https://laravel.com/docs', (string) $endpoint->get());
$this->assertSame('https://laravel.com/docs', (string) $endpoint);
}
/** @test */
public function it_can_build_endpoint_with_multiple_paths()
{
$endpoint = new Endpoint('https://laravel.com', ['docs', '5.4']);
$this->assertSame('https', $endpoint->getScheme());
$this->assertSame('laravel.com', $endpoint->getHost());
$this->assertSame('https://laravel.com', $endpoint->getUri());
$this->assertSame(['docs', '5.4'], $endpoint->getPath());
$this->assertSame([], $endpoint->getQuery());
$this->assertInstanceOf('GuzzleHttp\Psr7\Uri', $endpoint->get());
$this->assertSame('https://laravel.com/docs/5.4', (string) $endpoint->get());
$this->assertSame('https://laravel.com/docs/5.4', (string) $endpoint);
}
/** @test */
public function it_can_build_basic_endpoint_with_query_string()
{
$endpoint = new Endpoint('https://laravel.com', 'docs', ['search' => 'controller']);
$this->assertSame('https', $endpoint->getScheme());
$this->assertSame('laravel.com', $endpoint->getHost());
$this->assertSame('https://laravel.com', $endpoint->getUri());
$this->assertSame(['docs'], $endpoint->getPath());
$this->assertSame(['search' => 'controller'], $endpoint->getQuery());
$this->assertInstanceOf('GuzzleHttp\Psr7\Uri', $endpoint->get());
$this->assertSame('https://laravel.com/docs?search=controller', (string) $endpoint->get());
$this->assertSame('https://laravel.com/docs?search=controller', (string) $endpoint);
}
/** @test */
public function it_can_build_basic_endpoint_appended_query_string()
{
$uri = new Uri('https://laravel.com/docs?search=controller&page=3');
$endpoint = new Endpoint($uri);
$this->assertSame('https', $endpoint->getScheme());
$this->assertSame('laravel.com', $endpoint->getHost());
$this->assertSame('https://laravel.com', $endpoint->getUri());
$this->assertSame(['docs'], $endpoint->getPath());
$this->assertSame(['search' => 'controller', 'page' => '3'], $endpoint->getQuery());
$this->assertInstanceOf('GuzzleHttp\Psr7\Uri', $endpoint->get());
$this->assertSame('https://laravel.com/docs?search=controller&page=3', (string) $endpoint->get());
$this->assertSame('https://laravel.com/docs?search=controller&page=3', (string) $endpoint);
}
/** @test */
public function it_can_build_basic_endpoint_from_uri_instance()
{
$endpoint = (new Endpoint('https://laravel.com', 'docs'))
->addQuery(['search' => 'controller', 'page' => 3]);
$this->assertSame('https', $endpoint->getScheme());
$this->assertSame('laravel.com', $endpoint->getHost());
$this->assertSame('https://laravel.com', $endpoint->getUri());
$this->assertSame(['docs'], $endpoint->getPath());
$this->assertSame(['search' => 'controller', 'page' => '3'], $endpoint->getQuery());
$this->assertInstanceOf('GuzzleHttp\Psr7\Uri', $endpoint->get());
$this->assertSame('https://laravel.com/docs?search=controller&page=3', (string) $endpoint->get());
$this->assertSame('https://laravel.com/docs?search=controller&page=3', (string) $endpoint);
}
/** @test */
public function it_can_set_endpoint_with_no_uri()
{
$endpoint = new Endpoint(null, 'docs');
$this->assertSame('', $endpoint->getScheme());
$this->assertSame('', $endpoint->getHost());
$this->assertSame(null, $endpoint->getUri());
$this->assertSame(['docs'], $endpoint->getPath());
$this->assertSame([], $endpoint->getQuery());
$this->assertInstanceOf('GuzzleHttp\Psr7\Uri', $endpoint->get());
$this->assertSame('/docs', (string) $endpoint->get());
$this->assertSame('/docs', (string) $endpoint);
}
/**
* @test
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Method [getFullUrl] doesn't exists.
*/
public function it_cant_call_unknown_method_should_throw_exception()
{
(new Endpoint(null, 'docs'))->getFullUrl();
}
}