Skip to content

Commit

Permalink
Merge 0278d1c into 177f655
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Nov 3, 2020
2 parents 177f655 + 0278d1c commit eba42ed
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@
/phpunit.xml
/test/TestAsset/.cache/
/vendor/
.phpunit.result.cache
22 changes: 6 additions & 16 deletions .travis.yml
Expand Up @@ -13,38 +13,28 @@ env:
matrix:
fast_finish: true
include:
- php: 7.1
env:
- DEPS=lowest
- php: 7.1
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.2
env:
- DEPS=lowest
- php: 7.2
env:
- DEPS=latest
- php: 7.3
env:
- DEPS=lowest
- php: 7.3
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.4
env:
- DEPS=lowest
- php: 7.4
env:
- DEPS=latest
- php: 'nightly'
env:
- DEPS=latest

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- if [[ $TEST_COVERAGE != 'true' && $TRAVIS_PHP_VERSION != 'nightly' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi

install:
- travis_retry composer install $COMPOSER_ARGS
- 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
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Expand Up @@ -28,7 +28,7 @@
}
},
"require": {
"php": "^7.1",
"php": "^7.3 || ~8.0.0",
"laminas/laminas-zendframework-bridge": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0"
Expand All @@ -38,10 +38,11 @@
"ext-dom": "*",
"ext-gd": "*",
"ext-libxml": "*",
"http-interop/http-factory-tests": "^0.5.0",
"http-interop/http-factory-tests": "^0.8.0",
"laminas/laminas-coding-standard": "~1.0.0",
"php-http/psr7-integration-tests": "^1.0",
"phpunit/phpunit": "^7.5.18"
"php-http/psr7-integration-tests": "^1.1",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.1"
},
"provide": {
"psr/http-factory-implementation": "1.0",
Expand Down
15 changes: 15 additions & 0 deletions src/Exception/RuntimeException.php
@@ -0,0 +1,15 @@
<?php

/**
* @see https://github.com/laminas/laminas-diactoros for the canonical source repository
* @copyright https://github.com/laminas/laminas-diactoros/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-diactoros/blob/master/LICENSE.md New BSD License
*/

declare(strict_types=1);

namespace Laminas\Diactoros\Exception;

class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}
15 changes: 10 additions & 5 deletions src/Stream.php
Expand Up @@ -347,7 +347,7 @@ private function setStream($stream, string $mode = 'r') : void
}

if ($error) {
throw new Exception\InvalidArgumentException('Invalid stream reference provided');
throw new Exception\RuntimeException('Invalid stream reference provided');
}

if (! $this->isValidStreamResourceType($resource)) {
Expand All @@ -370,9 +370,14 @@ private function setStream($stream, string $mode = 'r') : void
*/
private function isValidStreamResourceType($resource): bool
{
return (
is_resource($resource) &&
in_array(get_resource_type($resource), self::ALLOWED_STREAM_RESOURCE_TYPES, true)
);
if (is_resource($resource)) {
return in_array(get_resource_type($resource), self::ALLOWED_STREAM_RESOURCE_TYPES, true);
}

if (PHP_VERSION_ID >= 80000 && $resource instanceof \GdImage) {
return true;
}

return false;
}
}
3 changes: 3 additions & 0 deletions test/RelativeStreamTest.php
Expand Up @@ -14,6 +14,7 @@
use Laminas\Diactoros\Stream;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use RuntimeException;

use const SEEK_SET;
Expand All @@ -23,6 +24,8 @@
*/
class RelativeStreamTest extends TestCase
{
use ProphecyTrait;

public function testToString()
{
$decorated = $this->prophesize(Stream::class);
Expand Down
8 changes: 4 additions & 4 deletions test/Request/SerializerTest.php
Expand Up @@ -54,8 +54,8 @@ public function testSerializesRequestWithBody()
->withBody($stream);

$message = Serializer::toString($request);
$this->assertContains("POST /foo/bar HTTP/1.1\r\n", $message);
$this->assertContains("\r\n\r\n" . $body, $message);
$this->assertStringContainsString("POST /foo/bar HTTP/1.1\r\n", $message);
$this->assertStringContainsString("\r\n\r\n" . $body, $message);
}

public function testSerializesMultipleHeadersCorrectly()
Expand All @@ -67,8 +67,8 @@ public function testSerializesMultipleHeadersCorrectly()
->withAddedHeader('X-Foo-Bar', 'Bat');

$message = Serializer::toString($request);
$this->assertContains("X-Foo-Bar: Baz", $message);
$this->assertContains("X-Foo-Bar: Bat", $message);
$this->assertStringContainsString("X-Foo-Bar: Baz", $message);
$this->assertStringContainsString("X-Foo-Bar: Bat", $message);
}

public function originForms()
Expand Down
4 changes: 2 additions & 2 deletions test/RequestTest.php
Expand Up @@ -342,7 +342,7 @@ public function testGetHeadersContainsHostHeaderIfUriWithHostIsPresent()
$request = new Request('http://example.com');
$headers = $request->getHeaders();
$this->assertArrayHasKey('Host', $headers);
$this->assertContains('example.com', $headers['Host']);
$this->assertStringContainsString('example.com', $headers['Host'][0]);
}

/**
Expand Down Expand Up @@ -421,7 +421,7 @@ public function testGetHostHeaderLineReturnsUriHostWhenPresent()
{
$request = new Request('http://example.com');
$header = $request->getHeaderLine('host');
$this->assertContains('example.com', $header);
$this->assertStringContainsString('example.com', $header);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/Response/HtmlResponseTest.php
Expand Up @@ -14,9 +14,12 @@
use Laminas\Diactoros\Response\HtmlResponse;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\StreamInterface;
use Prophecy\PhpUnit\ProphecyTrait;

class HtmlResponseTest extends TestCase
{
use ProphecyTrait;

public function testConstructorAcceptsHtmlString()
{
$body = '<html>Uh oh not found</html>';
Expand Down
2 changes: 1 addition & 1 deletion test/Response/JsonResponseTest.php
Expand Up @@ -128,7 +128,7 @@ public function testUsesSaneDefaultJsonEncodingFlags($value, $key)
$contents = (string) $stream;

$expected = json_encode($value, $defaultFlags);
$this->assertContains(
$this->assertStringContainsString(
$expected,
$contents,
sprintf('Did not encode %s properly; expected (%s), received (%s)', $key, $expected, $contents)
Expand Down
6 changes: 3 additions & 3 deletions test/Response/SerializerTest.php
Expand Up @@ -56,8 +56,8 @@ public function testSerializesMultipleHeadersCorrectly()
->withAddedHeader('X-Foo-Bar', 'Bat');

$message = Serializer::toString($response);
$this->assertContains("X-Foo-Bar: Baz", $message);
$this->assertContains("X-Foo-Bar: Bat", $message);
$this->assertStringContainsString("X-Foo-Bar: Baz", $message);
$this->assertStringContainsString("X-Foo-Bar: Bat", $message);
}

public function testOmitsReasonPhraseFromStatusLineIfEmpty()
Expand All @@ -68,7 +68,7 @@ public function testOmitsReasonPhraseFromStatusLineIfEmpty()
$response->getBody()->write('Content!');

$message = Serializer::toString($response);
$this->assertContains("HTTP/1.1 299\r\n", $message);
$this->assertStringContainsString("HTTP/1.1 299\r\n", $message);
}

public function testCanDeserializeBasicResponse()
Expand Down
3 changes: 3 additions & 0 deletions test/Response/TextResponseTest.php
Expand Up @@ -14,9 +14,12 @@
use Laminas\Diactoros\Response\TextResponse;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\StreamInterface;
use Prophecy\PhpUnit\ProphecyTrait;

class TextResponseTest extends TestCase
{
use ProphecyTrait;

public function testConstructorAcceptsBodyAsString()
{
$body = 'Uh oh not found';
Expand Down
3 changes: 3 additions & 0 deletions test/Response/XmlResponseTest.php
Expand Up @@ -14,11 +14,14 @@
use Laminas\Diactoros\Response\XmlResponse;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\StreamInterface;
use Prophecy\PhpUnit\ProphecyTrait;

use const PHP_EOL;

class XmlResponseTest extends TestCase
{
use ProphecyTrait;

public function testConstructorAcceptsBodyAsString()
{
$body = 'Super valid XML';
Expand Down
9 changes: 8 additions & 1 deletion test/StreamTest.php
Expand Up @@ -477,7 +477,6 @@ public function invalidResources()
'true' => [ true ],
'int' => [ 1 ],
'float' => [ 1.1 ],
'string-non-resource' => [ 'foo-bar-baz' ],
'array' => [ [ fopen($this->tmpnam, 'r+') ] ],
'object' => [ (object) [ 'resource' => fopen($this->tmpnam, 'r+') ] ],
];
Expand All @@ -494,6 +493,14 @@ public function testAttachWithNonStringNonResourceRaisesException($resource)
$this->stream->attach($resource);
}

public function testAttachWithInvalidStringResourceRaisesException()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Invalid stream');

$this->stream->attach('foo-bar-baz');
}

public function testAttachWithResourceAttachesResource()
{
$this->tmpnam = tempnam(sys_get_temp_dir(), 'diac');
Expand Down
21 changes: 17 additions & 4 deletions test/UriTest.php
Expand Up @@ -13,6 +13,7 @@
use InvalidArgumentException;
use Laminas\Diactoros\Uri;
use PHPUnit\Framework\TestCase;
use ReflectionObject;

use function sprintf;

Expand Down Expand Up @@ -468,10 +469,19 @@ public function testMutationResetsUriStringPropertyInClone($method, $value)
{
$uri = new Uri('http://example.com/path?query=string#fragment');
$string = (string) $uri;
$this->assertAttributeSame($string, 'uriString', $uri);

$r = new ReflectionObject($uri);
$p = $r->getProperty('uriString');
$p->setAccessible(true);
$this->assertSame($string, $p->getValue($uri));

$test = $uri->{$method}($value);
$this->assertAttributeInternalType('null', 'uriString', $test);
$this->assertAttributeSame($string, 'uriString', $uri);
$r2 = new ReflectionObject($uri);
$p2 = $r2->getProperty('uriString');
$p2->setAccessible(true);
$this->assertNull($p2->getValue($test));

$this->assertSame($string, $p->getValue($uri));
}

/**
Expand Down Expand Up @@ -662,7 +672,10 @@ public function testReservedCharsInPathUnencoded()
->withHost('api.linkedin.com')
->withPath('/v1/people/~:(first-name,last-name,email-address,picture-url)');

$this->assertContains('/v1/people/~:(first-name,last-name,email-address,picture-url)', (string) $uri);
$this->assertStringContainsString(
'/v1/people/~:(first-name,last-name,email-address,picture-url)',
(string) $uri
);
}

public function testHostIsLowercase()
Expand Down

0 comments on commit eba42ed

Please sign in to comment.