11<?php
22
3- use MaplePHP \Http \Environment ;
43use MaplePHP \Http \Request ;
5- use MaplePHP \Http \ServerRequest ;
6- use MaplePHP \Http \ServerRequestTest ;
74use MaplePHP \Http \Uri ;
8- use MaplePHP \Http \UriTest ;
9- use MaplePHP \Unitary \Mocker \MethodRegistry ;
5+ use MaplePHP \Unitary \Expect ;
106use MaplePHP \Unitary \TestCase ;
117
128$ unit = new MaplePHP \Unitary \Unit ();
139
1410// If you build your library right it will become very easy to mock, like I have below.
1511
1612// Begin by adding a test
17- $ unit ->case ("MaplePHP Request URI path test " , function (TestCase $ inst ) {
13+ $ unit ->case ("MaplePHP Request URI path test " , function (TestCase $ case ) {
1814
1915 $ request = new Request (
2016 "POST " , // The HTTP Method (GET, POST, PUT, DELETE, PATCH)
2319 ["email " => "john.doe@example.com " ] // Post data
2420 );
2521
26- $ inst ->add ($ request ->getMethod (), function () {
27- return $ this ->equal ("GET " );
22+ $ case
23+ ->error ("HTTP Request method is not POST " )
24+ ->validate ($ request ->getMethod (), function (Expect $ inst ) {
25+ $ inst ->isEqualTo ("POST " );
26+ //assert($inst->isEqualTo("GET")->isValid(), "wdqwwdqw dwq wqdwq");
27+ });
2828
29- }, "HTTP Request method Type is not POST " );
30- // Adding an error message is not required, but it is highly recommended
31-
32- $ this ->add ($ request ->getUri ()->getPort (), [
33- "isInt " => [], // Has no arguments = empty array
34- "min " => [1 ], // Strict way is to pass each argument to array
35- "max " => 65535 , // But if its only one argument then this it is acceptable
36- "length " => [1 , 5 ]
37-
38- ], "Is not a valid port number " );
29+ $ case ->validate ($ request ->getUri ()->getPort (), function (Expect $ inst ) {
30+ $ inst ->isInt ();
31+ $ inst ->min (1 );
32+ $ inst ->max (65535 );
33+ $ inst ->length (1 , 5 );
34+ });
3935
4036 $ this ->add ($ request ->getUri ()->getUserInfo (), [
4137 "isString " => [],
4642
4743 ], "Is not a valid port number " );
4844
49- $ this ->add ((string )$ request ->withUri (new \ MaplePHP \ Http \ Uri ("https://example.se " ))->getUri (), [
45+ $ this ->add ((string )$ request ->withUri (new Uri ("https://example.se " ))->getUri (), [
5046 "equal " => ["https://example.se " ],
5147 ], "GetUri expects https://example.se as result " );
5248});
0 commit comments