3
3
$ unit = new MaplePHP \Unitary \Unit ();
4
4
5
5
// If you build your library right it will become very easy to mock, like I have below.
6
- $ request = new MaplePHP \Http \Request (
7
- "POST " , // The HTTP Method (GET, POST, PUT, DELETE, PATCH)
8
- "https://admin:[email protected] :65535/test.php?id=5221&place=stockholm " ,
// The Request URI
9
- ["Content-Type " => "application/x-www-form-urlencoded " ], // Add Headers, empty array is allowed
10
- [
"email " =>
"[email protected] " ]
// Post data
11
- );
12
6
13
7
// Begin by adding a test
14
- $ unit ->case ("MaplePHP Request URI path test " , function () use ($ request ) {
8
+ $ unit ->case ("MaplePHP Request URI path test " , function () {
9
+ $ request = new MaplePHP \Http \Request (
10
+ "POST " , // The HTTP Method (GET, POST, PUT, DELETE, PATCH)
11
+ "https://admin:[email protected] :65535/test.php?id=5221&place=stockholm " ,
// The Request URI
12
+ ["Content-Type " => "application/x-www-form-urlencoded " ], // Add Headers, empty array is allowed
13
+ [
"email " =>
"[email protected] " ]
// Post data
14
+ );
15
15
16
- // Test 1
17
16
$ this ->add ($ request ->getMethod (), function () {
18
17
return $ this ->equal ("POST " );
19
18
20
19
}, "HTTP Request method Type is not POST " );
21
- // Adding a error message is not required, but it is highly recommended
20
+ // Adding an error message is not required, but it is highly recommended
22
21
23
- // Test 2
24
22
$ this ->add ($ request ->getUri ()->getPort (), [
25
23
"isInt " => [], // Has no arguments = empty array
26
24
"min " => [1 ], // Strict way is to pass each argument to array
29
27
30
28
], "Is not a valid port number " );
31
29
32
- // Test 3
33
30
$ this ->add ($ request ->getUri ()->getUserInfo (), [
34
31
"isString " => [],
35
32
"User validation " => function ($ value ) {
38
35
}
39
36
40
37
], "Is not a valid port number " );
41
- });
42
38
43
- $ unit ->execute ();
39
+ $ this ->add ((string )$ request ->withUri (new \MaplePHP \Http \Uri ("https://example.se " ))->getUri (), [
40
+ "equal " => ["https://example.se " ],
41
+ ], "GetUri expects https://example.se as result " );
42
+ });
0 commit comments