-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
14 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,24 +3,22 @@ | |
$unit = new MaplePHP\Unitary\Unit(); | ||
|
||
// If you build your library right it will become very easy to mock, like I have below. | ||
$request = new MaplePHP\Http\Request( | ||
"POST", // The HTTP Method (GET, POST, PUT, DELETE, PATCH) | ||
"https://admin:[email protected]:65535/test.php?id=5221&place=stockholm", // The Request URI | ||
["Content-Type" => "application/x-www-form-urlencoded"], // Add Headers, empty array is allowed | ||
["email" => "[email protected]"] // Post data | ||
); | ||
|
||
// Begin by adding a test | ||
$unit->case("MaplePHP Request URI path test", function() use($request) { | ||
$unit->case("MaplePHP Request URI path test", function() { | ||
$request = new MaplePHP\Http\Request( | ||
"POST", // The HTTP Method (GET, POST, PUT, DELETE, PATCH) | ||
"https://admin:[email protected]:65535/test.php?id=5221&place=stockholm", // The Request URI | ||
["Content-Type" => "application/x-www-form-urlencoded"], // Add Headers, empty array is allowed | ||
["email" => "[email protected]"] // Post data | ||
); | ||
|
||
// Test 1 | ||
$this->add($request->getMethod(), function() { | ||
return $this->equal("POST"); | ||
|
||
}, "HTTP Request method Type is not POST"); | ||
// Adding a error message is not required, but it is highly recommended | ||
// Adding an error message is not required, but it is highly recommended | ||
|
||
// Test 2 | ||
$this->add($request->getUri()->getPort(), [ | ||
"isInt" => [], // Has no arguments = empty array | ||
"min" => [1], // Strict way is to pass each argument to array | ||
|
@@ -29,7 +27,6 @@ | |
|
||
], "Is not a valid port number"); | ||
|
||
// Test 3 | ||
$this->add($request->getUri()->getUserInfo(), [ | ||
"isString" => [], | ||
"User validation" => function($value) { | ||
|
@@ -38,6 +35,8 @@ | |
} | ||
|
||
], "Is not a valid port number"); | ||
}); | ||
|
||
$unit->execute(); | ||
$this->add((string)$request->withUri(new \MaplePHP\Http\Uri("https://example.se"))->getUri(), [ | ||
"equal" => ["https://example.se"], | ||
], "GetUri expects https://example.se as result"); | ||
}); |