Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psr7 integration tests #32

Merged
merged 2 commits into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.5",
"phpunit/phpunit": "^5.7|^6.0"
"phpunit/phpunit": "^5.7|^6.0",
"php-http/psr7-integration-tests": "dev-master"
},
"provide": {
"psr/http-message-implementation": "1.0"
Expand Down
4 changes: 2 additions & 2 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function __construct(
$password = ''
) {
$this->scheme = $this->filterScheme($scheme);
$this->host = $host;
$this->host = strtolower($host);
$this->port = $this->filterPort($port);
$this->path = empty($path) ? '/' : $this->filterPath($path);
$this->query = $this->filterQuery($query);
Expand Down Expand Up @@ -390,7 +390,7 @@ public function getHost()
public function withHost($host)
{
$clone = clone $this;
$clone->host = $host;
$clone->host = strtolower($host);

return $clone;
}
Expand Down
51 changes: 51 additions & 0 deletions tests/Integration/BaseTestFactories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Slim Framework (https://slimframework.com)
*
* @link https://github.com/slimphp/Slim-Http
* @copyright Copyright (c) 2011-2017 Josh Lockhart
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
*/
namespace Slim\Tests\Http\Integration;

use Slim\Http\Stream;
use Slim\Http\UploadedFile;
use Slim\Http\Uri;

trait BaseTestFactories
{

/**
* @param $uri
* @return Uri
*/
protected function buildUri($uri)
{
return Uri::createFromString($uri);
}

/**
* @param $data
* @return Stream
*/
protected function buildStream($data)
{
if (!is_resource($data)) {
$h = fopen('php://temp', 'w+');
fwrite($h, $data);

$data = $h;
}

return new Stream($data);
}

/**
* @param $data
* @return UploadedFile
*/
protected function buildUploadableFile($data)
{
return new UploadedFile($data);
}
}
26 changes: 26 additions & 0 deletions tests/Integration/ResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Slim Framework (https://slimframework.com)
*
* @link https://github.com/slimphp/Slim-Http
* @copyright Copyright (c) 2011-2017 Josh Lockhart
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
*/
namespace Slim\Tests\Http\Integration;

use Http\Psr7Test\ResponseIntegrationTest;
use Psr\Http\Message\ResponseInterface;
use Slim\Http\Response;

class ResponseTest extends ResponseIntegrationTest
{
use BaseTestFactories;

/**
* @return ResponseInterface that is used in the tests
*/
public function createSubject()
{
return new Response();
}
}
27 changes: 27 additions & 0 deletions tests/Integration/ServerRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Slim Framework (https://slimframework.com)
*
* @link https://github.com/slimphp/Slim-Http
* @copyright Copyright (c) 2011-2017 Josh Lockhart
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
*/
namespace Slim\Tests\Http\Integration;

use Psr\Http\Message\ServerRequestInterface;
use Slim\Http\Headers;
use Slim\Http\Request;
use Http\Psr7Test\ServerRequestIntegrationTest;

class ServerRequestTest extends ServerRequestIntegrationTest
{
use BaseTestFactories;

/**
* @return ServerRequestInterface that is used in the tests
*/
public function createSubject()
{
return new Request('GET', $this->buildUri('/'), new Headers(), [], $_SERVER, $this->buildStream(''));
}
}
38 changes: 38 additions & 0 deletions tests/Integration/StreamTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Slim Framework (https://slimframework.com)
*
* @link https://github.com/slimphp/Slim-Http
* @copyright Copyright (c) 2011-2017 Josh Lockhart
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
*/
namespace Slim\Tests\Http\Integration;

use Http\Psr7Test\StreamIntegrationTest;
use Psr\Http\Message\StreamInterface;
use Slim\Http\Stream;

class StreamTest extends StreamIntegrationTest
{
use BaseTestFactories;

/**
* @param string|resource|StreamInterface $data
*
* @return StreamInterface
*/
public function createStream($data)
{
if ($data instanceof StreamInterface) {
return $data;
} elseif (is_resource($data)) {
return new Stream($data);
} elseif (is_string($data)) {
$s = fopen('php://temp', 'w+');
fwrite($s, $data);
return new Stream($s);
}

throw new \InvalidArgumentException();
}
}
26 changes: 26 additions & 0 deletions tests/Integration/UploadedFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Slim Framework (https://slimframework.com)
*
* @link https://github.com/slimphp/Slim-Http
* @copyright Copyright (c) 2011-2017 Josh Lockhart
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
*/
namespace Slim\Tests\Http\Integration;

use Http\Psr7Test\UploadedFileIntegrationTest;
use Psr\Http\Message\UploadedFileInterface;
use Slim\Http\UploadedFile;

class UploadedFileTest extends UploadedFileIntegrationTest
{
use BaseTestFactories;

/**
* @return UploadedFileInterface that is used in the tests
*/
public function createSubject()
{
return new UploadedFile(tmpfile());
}
}
28 changes: 28 additions & 0 deletions tests/Integration/UriTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Slim Framework (https://slimframework.com)
*
* @link https://github.com/slimphp/Slim-Http
* @copyright Copyright (c) 2011-2017 Josh Lockhart
* @license https://github.com/slimphp/Slim-Http/blob/master/LICENSE (MIT License)
*/
namespace Slim\Tests\Http\Integration;

use Http\Psr7Test\UriIntegrationTest;
use Psr\Http\Message\UriInterface;
use Slim\Http\Uri;

class UriTest extends UriIntegrationTest
{
use BaseTestFactories;

/**
* @param string $uri
*
* @return UriInterface
*/
public function createUri($uri)
{
return Uri::createFromString($uri);
}
}