33$ unit = new MaplePHP \Unitary \Unit ();
44
55// 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- );
126
137// 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+ );
1515
16- // Test 1
1716 $ this ->add ($ request ->getMethod (), function () {
1817 return $ this ->equal ("POST " );
1918
2019 }, "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
2221
23- // Test 2
2422 $ this ->add ($ request ->getUri ()->getPort (), [
2523 "isInt " => [], // Has no arguments = empty array
2624 "min " => [1 ], // Strict way is to pass each argument to array
2927
3028 ], "Is not a valid port number " );
3129
32- // Test 3
3330 $ this ->add ($ request ->getUri ()->getUserInfo (), [
3431 "isString " => [],
3532 "User validation " => function ($ value ) {
3835 }
3936
4037 ], "Is not a valid port number " );
41- });
4238
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