Skip to content

Commit 37e80cc

Browse files
committed
Merge branch 'danopz-psr7-integration'
Closes slimphp#32
2 parents 344d8de + ab9f1f7 commit 37e80cc

8 files changed

+200
-3
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
},
2929
"require-dev": {
3030
"squizlabs/php_codesniffer": "^2.5",
31-
"phpunit/phpunit": "^5.7|^6.0"
31+
"phpunit/phpunit": "^5.7|^6.0",
32+
"php-http/psr7-integration-tests": "dev-master"
3233
},
3334
"provide": {
3435
"psr/http-message-implementation": "1.0"

src/Uri.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function __construct(
112112
$password = ''
113113
) {
114114
$this->scheme = $this->filterScheme($scheme);
115-
$this->host = $host;
115+
$this->host = strtolower($host);
116116
$this->port = $this->filterPort($port);
117117
$this->path = empty($path) ? '/' : $this->filterPath($path);
118118
$this->query = $this->filterQuery($query);
@@ -390,7 +390,7 @@ public function getHost()
390390
public function withHost($host)
391391
{
392392
$clone = clone $this;
393-
$clone->host = $host;
393+
$clone->host = strtolower($host);
394394

395395
return $clone;
396396
}
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Slim Framework (https://slimframework.com)
4+
*
5+
* @link https://github.com/slimphp/Slim-Http
6+
* @copyright Copyright (c) 2011-2017 Josh Lockhart
7+
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
8+
*/
9+
namespace Slim\Tests\Http\Integration;
10+
11+
use Slim\Http\Stream;
12+
use Slim\Http\UploadedFile;
13+
use Slim\Http\Uri;
14+
15+
trait BaseTestFactories
16+
{
17+
18+
/**
19+
* @param $uri
20+
* @return Uri
21+
*/
22+
protected function buildUri($uri)
23+
{
24+
return Uri::createFromString($uri);
25+
}
26+
27+
/**
28+
* @param $data
29+
* @return Stream
30+
*/
31+
protected function buildStream($data)
32+
{
33+
if (!is_resource($data)) {
34+
$h = fopen('php://temp', 'w+');
35+
fwrite($h, $data);
36+
37+
$data = $h;
38+
}
39+
40+
return new Stream($data);
41+
}
42+
43+
/**
44+
* @param $data
45+
* @return UploadedFile
46+
*/
47+
protected function buildUploadableFile($data)
48+
{
49+
return new UploadedFile($data);
50+
}
51+
}

tests/Integration/ResponseTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Slim Framework (https://slimframework.com)
4+
*
5+
* @link https://github.com/slimphp/Slim-Http
6+
* @copyright Copyright (c) 2011-2017 Josh Lockhart
7+
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
8+
*/
9+
namespace Slim\Tests\Http\Integration;
10+
11+
use Http\Psr7Test\ResponseIntegrationTest;
12+
use Psr\Http\Message\ResponseInterface;
13+
use Slim\Http\Response;
14+
15+
class ResponseTest extends ResponseIntegrationTest
16+
{
17+
use BaseTestFactories;
18+
19+
/**
20+
* @return ResponseInterface that is used in the tests
21+
*/
22+
public function createSubject()
23+
{
24+
return new Response();
25+
}
26+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Slim Framework (https://slimframework.com)
4+
*
5+
* @link https://github.com/slimphp/Slim-Http
6+
* @copyright Copyright (c) 2011-2017 Josh Lockhart
7+
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
8+
*/
9+
namespace Slim\Tests\Http\Integration;
10+
11+
use Psr\Http\Message\ServerRequestInterface;
12+
use Slim\Http\Headers;
13+
use Slim\Http\Request;
14+
use Http\Psr7Test\ServerRequestIntegrationTest;
15+
16+
class ServerRequestTest extends ServerRequestIntegrationTest
17+
{
18+
use BaseTestFactories;
19+
20+
/**
21+
* @return ServerRequestInterface that is used in the tests
22+
*/
23+
public function createSubject()
24+
{
25+
return new Request('GET', $this->buildUri('/'), new Headers(), [], $_SERVER, $this->buildStream(''));
26+
}
27+
}

tests/Integration/StreamTest.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Slim Framework (https://slimframework.com)
4+
*
5+
* @link https://github.com/slimphp/Slim-Http
6+
* @copyright Copyright (c) 2011-2017 Josh Lockhart
7+
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
8+
*/
9+
namespace Slim\Tests\Http\Integration;
10+
11+
use Http\Psr7Test\StreamIntegrationTest;
12+
use Psr\Http\Message\StreamInterface;
13+
use Slim\Http\Stream;
14+
15+
class StreamTest extends StreamIntegrationTest
16+
{
17+
use BaseTestFactories;
18+
19+
/**
20+
* @param string|resource|StreamInterface $data
21+
*
22+
* @return StreamInterface
23+
*/
24+
public function createStream($data)
25+
{
26+
if ($data instanceof StreamInterface) {
27+
return $data;
28+
} elseif (is_resource($data)) {
29+
return new Stream($data);
30+
} elseif (is_string($data)) {
31+
$s = fopen('php://temp', 'w+');
32+
fwrite($s, $data);
33+
return new Stream($s);
34+
}
35+
36+
throw new \InvalidArgumentException();
37+
}
38+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Slim Framework (https://slimframework.com)
4+
*
5+
* @link https://github.com/slimphp/Slim-Http
6+
* @copyright Copyright (c) 2011-2017 Josh Lockhart
7+
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
8+
*/
9+
namespace Slim\Tests\Http\Integration;
10+
11+
use Http\Psr7Test\UploadedFileIntegrationTest;
12+
use Psr\Http\Message\UploadedFileInterface;
13+
use Slim\Http\UploadedFile;
14+
15+
class UploadedFileTest extends UploadedFileIntegrationTest
16+
{
17+
use BaseTestFactories;
18+
19+
/**
20+
* @return UploadedFileInterface that is used in the tests
21+
*/
22+
public function createSubject()
23+
{
24+
return new UploadedFile(tmpfile());
25+
}
26+
}

tests/Integration/UriTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Slim Framework (https://slimframework.com)
4+
*
5+
* @link https://github.com/slimphp/Slim-Http
6+
* @copyright Copyright (c) 2011-2017 Josh Lockhart
7+
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
8+
*/
9+
namespace Slim\Tests\Http\Integration;
10+
11+
use Http\Psr7Test\UriIntegrationTest;
12+
use Psr\Http\Message\UriInterface;
13+
use Slim\Http\Uri;
14+
15+
class UriTest extends UriIntegrationTest
16+
{
17+
use BaseTestFactories;
18+
19+
/**
20+
* @param string $uri
21+
*
22+
* @return UriInterface
23+
*/
24+
public function createUri($uri)
25+
{
26+
return Uri::createFromString($uri);
27+
}
28+
}

0 commit comments

Comments
 (0)