Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge 62124e0 into 3e4edb8
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Sep 5, 2018
2 parents 3e4edb8 + 62124e0 commit 36edb95
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 4 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ cache:
env:
global:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="php-coveralls/php-coveralls"
- LEGACY_DEPS="phpunit/phpunit"

matrix:
Expand All @@ -31,6 +30,7 @@ matrix:
- DEPS=locked
- CHECK_CS=true
- TEST_COVERAGE=true
- INTEGRATION_DEPS="php-coveralls/php-coveralls"
- php: 7
env:
- DEPS=latest
Expand All @@ -52,6 +52,10 @@ matrix:
- php: 7.2
env:
- DEPS=latest
- php: 7.2
name: Integration tests
env:
- INTEGRATION_DEPS="http-interop/http-factory-diactoros"

before_install:
- if [[ $TEST_COVERAGE != 'true' && "$(php --version | grep xdebug -ci)" -ge 1 ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
Expand All @@ -62,7 +66,7 @@ install:
- if [[ $TRAVIS_PHP_VERSION =~ ^5.6 ]]; then travis_retry composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi
- if [[ $INTEGRATION_DEPS != '' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $INTEGRATION_DEPS ; fi
- stty cols 120 && composer show

script:
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"require-dev": {
"ext-dom": "*",
"ext-libxml": "*",
"php-http/psr7-integration-tests": "dev-master",
"phpunit/phpunit": "^5.7.16 || ^6.0.8 || ^7.2.7",
"zendframework/zend-coding-standard": "~1.0"
},
Expand Down
9 changes: 9 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<php>
<const name="REQUEST_FACTORY" value="Http\Factory\Diactoros\RequestFactory"/>
<const name="RESPONSE_FACTORY" value="Http\Factory\Diactoros\ResponseFactory"/>
<const name="SERVER_REQUEST_FACTORY" value="Http\Factory\Diactoros\ServerRequestFactory"/>
<const name="STREAM_FACTORY" value="Http\Factory\Diactoros\StreamFactory"/>
<const name="UPLOADED_FILE_FACTORY" value="Http\Factory\Diactoros\UploadedFileFactory"/>
<const name="URI_FACTORY" value="Http\Factory\Diactoros\UriFactory"/>
</php>
</phpunit>
9 changes: 8 additions & 1 deletion src/MessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,18 @@ private function filterHeaderValue($values)
$values = [$values];
}

if ([] === $values) {
throw new InvalidArgumentException(
'Invalid header value: must be a string or array of strings; '
. 'cannot be an empty array'
);
}

return array_map(function ($value) {
HeaderSecurity::assertValid($value);

return (string) $value;
}, $values);
}, array_values($values));
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ public function getParsedBody()
*/
public function withParsedBody($data)
{
if (! is_array($data) && ! is_object($data) && null !== $data) {
throw new InvalidArgumentException(sprintf(
'%s expects a null, array, or object argument; received %s',
__METHOD__,
gettype($data)
));
}

$new = clone $this;
$new->parsedBody = $data;
return $new;
Expand Down
2 changes: 1 addition & 1 deletion src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function withUserInfo($user, $password = null)
}

$info = $this->filterUserInfoPart($user);
if ($password) {
if (null !== $password) {
$info .= ':' . $this->filterUserInfoPart($password);
}

Expand Down
28 changes: 28 additions & 0 deletions test/Integration/RequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Diactoros\Integration;

use Http\Factory\Diactoros\RequestFactory;
use Http\Psr7Test\RequestIntegrationTest;
use Zend\Diactoros\Request;

class RequestTest extends RequestIntegrationTest
{
public static function setUpBeforeClass()
{
if (! class_exists(RequestFactory::class)) {
self::markTestSkipped('You need to install http-interop/http-factory-diactoros to run integration tests');
}
parent::setUpBeforeClass();
}

public function createSubject()
{
return new Request('/', 'GET');
}
}
28 changes: 28 additions & 0 deletions test/Integration/ResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Diactoros\Integration;

use Http\Factory\Diactoros\RequestFactory;
use Http\Psr7Test\ResponseIntegrationTest;
use Zend\Diactoros\Response;

class ResponseTest extends ResponseIntegrationTest
{
public static function setUpBeforeClass()
{
if (! class_exists(RequestFactory::class)) {
self::markTestSkipped('You need to install http-interop/http-factory-diactoros to run integration tests');
}
parent::setUpBeforeClass();
}

public function createSubject()
{
return new Response();
}
}
28 changes: 28 additions & 0 deletions test/Integration/ServerRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Diactoros\Integration;

use Http\Factory\Diactoros\RequestFactory;
use Http\Psr7Test\ServerRequestIntegrationTest;
use Zend\Diactoros\ServerRequest;

class ServerRequestTest extends ServerRequestIntegrationTest
{
public static function setUpBeforeClass()
{
if (! class_exists(RequestFactory::class)) {
self::markTestSkipped('You need to install http-interop/http-factory-diactoros to run integration tests');
}
parent::setUpBeforeClass();
}

public function createSubject()
{
return new ServerRequest($_SERVER);
}
}
33 changes: 33 additions & 0 deletions test/Integration/StreamTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Diactoros\Integration;

use Http\Factory\Diactoros\RequestFactory;
use Http\Psr7Test\StreamIntegrationTest;
use Psr\Http\Message\StreamInterface;
use Zend\Diactoros\Stream;

class StreamTest extends StreamIntegrationTest
{
public static function setUpBeforeClass()
{
if (! class_exists(RequestFactory::class)) {
self::markTestSkipped('You need to install http-interop/http-factory-diactoros to run integration tests');
}
parent::setUpBeforeClass();
}

public function createStream($data)
{
if ($data instanceof StreamInterface) {
return $data;
}

return new Stream($data);
}
}
32 changes: 32 additions & 0 deletions test/Integration/UploadedFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Diactoros\Integration;

use Http\Factory\Diactoros\RequestFactory;
use Http\Psr7Test\UploadedFileIntegrationTest;
use Zend\Diactoros\Stream;
use Zend\Diactoros\UploadedFile;

class UploadedFileTest extends UploadedFileIntegrationTest
{
public static function setUpBeforeClass()
{
if (! class_exists(RequestFactory::class)) {
self::markTestSkipped('You need to install http-interop/http-factory-diactoros to run integration tests');
}
parent::setUpBeforeClass();
}

public function createSubject()
{
$stream = new Stream('php://memory', 'rw');
$stream->write('foobar');

return new UploadedFile($stream, $stream->getSize(), UPLOAD_ERR_OK);
}
}
28 changes: 28 additions & 0 deletions test/Integration/UriTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Diactoros\Integration;

use Http\Factory\Diactoros\RequestFactory;
use Http\Psr7Test\UriIntegrationTest;
use Zend\Diactoros\Uri;

class UriTest extends UriIntegrationTest
{
public static function setUpBeforeClass()
{
if (! class_exists(RequestFactory::class)) {
self::markTestSkipped('You need to install http-interop/http-factory-diactoros to run integration tests');
}
parent::setUpBeforeClass();
}

public function createUri($uri)
{
return new Uri($uri);
}
}

0 comments on commit 36edb95

Please sign in to comment.