Skip to content

Commit 63012fe

Browse files
committed
Minor clean up
1 parent 41ed502 commit 63012fe

5 files changed

Lines changed: 77 additions & 23 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
._*
22
.DS_Store
33
.sass-cache
4-
vendor
4+
composer.lock
5+
vendor
6+
.idea/

Stream.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ class Stream implements StreamInterface
3535

3636
/**
3737
* PSR-7 Stream
38-
* @param mixed $stream
39-
* @param string $permission Default stream permission is r+
38+
*
39+
* @param mixed $stream
40+
* @param string $permission The default stream permission is r+
4041
*/
4142
public function __construct(mixed $stream = null, string $permission = "r+")
4243
{

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@
3939
"MaplePHP\\Http\\": ""
4040
}
4141
},
42-
"minimum-stability": "dev"
42+
"minimum-stability": "dev",
43+
"scripts": {
44+
"unitary": "php vendor/bin/unitary"
45+
}
4346
}

tests/unitary-request.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
<?php
22

3-
use MaplePHP\Http\Environment;
43
use MaplePHP\Http\Request;
5-
use MaplePHP\Http\ServerRequest;
6-
use MaplePHP\Http\ServerRequestTest;
74
use MaplePHP\Http\Uri;
8-
use MaplePHP\Http\UriTest;
9-
use MaplePHP\Unitary\Mocker\MethodRegistry;
5+
use MaplePHP\Unitary\Expect;
106
use 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)
@@ -23,19 +19,19 @@
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" => [],
@@ -46,7 +42,7 @@
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
});

tests/unitaryRequest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
use MaplePHP\Http\Environment;
4+
use MaplePHP\Http\Request;
5+
use MaplePHP\Http\ServerRequest;
6+
use MaplePHP\Http\ServerRequestTest;
7+
use MaplePHP\Http\Uri;
8+
use MaplePHP\Http\UriTest;
9+
use MaplePHP\Unitary\Mocker\MethodRegistry;
10+
use MaplePHP\Unitary\TestCase;
11+
12+
$unit = new MaplePHP\Unitary\Unit();
13+
14+
// If you build your library right it will become very easy to mock, like I have below.
15+
16+
// Begin by adding a test
17+
$unit->case("MaplePHP Request URI path test", function(TestCase $inst) {
18+
19+
$request = new Request(
20+
"POST", // The HTTP Method (GET, POST, PUT, DELETE, PATCH)
21+
"https://admin:mypass@example.com:65535/test.php?id=5221&place=stockholm", // The Request URI
22+
["Content-Type" => "application/x-www-form-urlencoded"], // Add Headers, empty array is allowed
23+
["email" => "john.doe@example.com"] // Post data
24+
);
25+
26+
$inst->add($request->getMethod(), function() {
27+
return $this->equal("GET");
28+
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");
39+
40+
$this->add($request->getUri()->getUserInfo(), [
41+
"isString" => [],
42+
"User validation" => function($value) {
43+
$arr = explode(":", $value);
44+
return ($this->withValue($arr[0])->equal("admin") && $this->withValue($arr[1])->equal("mypass"));
45+
}
46+
47+
], "Is not a valid port number");
48+
49+
$this->add((string)$request->withUri(new \MaplePHP\Http\Uri("https://example.se"))->getUri(), [
50+
"equal" => ["https://example.se"],
51+
], "GetUri expects https://example.se as result");
52+
});

0 commit comments

Comments
 (0)