|
1
|
|
|
<?php |
|
2
|
|
|
namespace spec\Subreality\Dilmun\Anshar\Http; |
|
3
|
|
|
|
|
4
|
|
|
use Subreality\Dilmun\Anshar\Http\Uri; |
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
|
6
|
|
|
use Prophecy\Argument; |
|
7
|
|
|
|
|
8
|
|
|
class UriSpec extends ObjectBehavior |
|
9
|
|
|
{ |
|
10
|
|
|
function let() |
|
11
|
|
|
{ |
|
12
|
|
|
$this->beConstructedWith("foo://bar:[email protected]:8042/over/there?name=ferret#nose"); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
function it_is_initializable() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->shouldHaveType(Uri::class); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
function it_throws_an_exception_when_constructed_with_a_non_string() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->shouldThrow('\InvalidArgumentException')->during('__construct', array(123)); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
function its_properties_are_constructed_from_a_string_during_construction() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->getScheme()->shouldReturn("foo"); |
|
28
|
|
|
/* |
|
29
|
|
|
$this->getAuthority()->shouldReturn("bar:[email protected]:8042"); |
|
30
|
|
|
$this->getUserInfo()->shouldReturn("bar:baz"); |
|
31
|
|
|
$this->getHost()->shouldReturn("example.com"); |
|
32
|
|
|
$this->getPort()->shouldReturn(8042); |
|
33
|
|
|
$this->getPath()->shouldReturn("/over/there"); |
|
34
|
|
|
$this->getQuery()->shouldReturn("name=ferret"); |
|
35
|
|
|
$this->getFragment()->shouldReturn("nose"); |
|
36
|
|
|
*/ |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/* function it_returns_an_empty_string_when_it_has_no_scheme() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->getScheme()->shouldReturn(""); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_returns_a_lowercase_string_when_it_has_a_scheme() |
|
45
|
|
|
{ |
|
46
|
|
|
$mixed_case = "HtTp"; |
|
47
|
|
|
|
|
48
|
|
|
$lower_case = "http"; |
|
49
|
|
|
|
|
50
|
|
|
$this->getScheme()->shouldReturn($lower_case); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_does_not_return_a_scheme_that_ends_in_a_colon() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->getScheme()->shouldNotEndWith(":"); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function it_returns_an_empty_string_when_it_has_no_authority() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->getAuthority()->shouldReturn(""); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
function it_returns_authority_data_including_user_info_when_it_has_user_info() |
|
64
|
|
|
{ |
|
65
|
|
|
$user_info = "baz"; |
|
66
|
|
|
$host = "www.foo.bar"; |
|
67
|
|
|
$port = 8080; |
|
68
|
|
|
|
|
69
|
|
|
$authority_syntax = "{$user_info}@{$host}:{$port}"; |
|
70
|
|
|
|
|
71
|
|
|
$this->getAuthority()->shouldReturn($authority_syntax); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
function it_returns_authority_data_without_user_info_when_it_has_no_user_info() |
|
75
|
|
|
{ |
|
76
|
|
|
$host = "www.foo.bar"; |
|
77
|
|
|
$port = 8080; |
|
78
|
|
|
|
|
79
|
|
|
$authority_syntax = "{$host}:{$port}"; |
|
80
|
|
|
|
|
81
|
|
|
$this->getAuthority()->shouldReturn($authority_syntax); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
function it_returns_authority_data_including_port_when_it_has_nonstandard_port() |
|
85
|
|
|
{ |
|
86
|
|
|
$host = "www.foo.bar"; |
|
87
|
|
|
$port = 8080; |
|
88
|
|
|
|
|
89
|
|
|
$authority_syntax = "{$host}:{$port}"; |
|
90
|
|
|
|
|
91
|
|
|
$this->getAuthority()->shouldReturn($authority_syntax); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
function it_returns_authority_data_excluding_port_when_it_has_standard_port() |
|
95
|
|
|
{ |
|
96
|
|
|
$host = "www.foo.bar"; |
|
97
|
|
|
|
|
98
|
|
|
$authority_syntax = $host; |
|
99
|
|
|
|
|
100
|
|
|
$this->getAuthority()->shouldReturn($authority_syntax); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
function it_returns_authority_data_without_port_when_it_has_no_port() |
|
104
|
|
|
{ |
|
105
|
|
|
$host = "www.foo.bar"; |
|
106
|
|
|
|
|
107
|
|
|
$authority_syntax = $host; |
|
108
|
|
|
|
|
109
|
|
|
$this->getAuthority()->shouldReturn($authority_syntax); |
|
110
|
|
|
}*/ |
|
111
|
|
|
} |
|
112
|
|
|
|