Skip to content

Commit

Permalink
Added PHP 8.0 support #4
Browse files Browse the repository at this point in the history
Signed-off-by: Vytautas Stankus <svycka@gmail.com>
  • Loading branch information
svycka committed Nov 4, 2020
1 parent 69c3f45 commit d4486ed
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/coveralls-upload.json
/phpunit.xml
/vendor/
.phpunit.result.cache
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ cache:

env:
global:
- COMPOSER_ARGS="--no-interaction"
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"
- COVERAGE_DEPS="php-coveralls/php-coveralls"

matrix:
fast_finish: true
include:
- php: 7.1
- php: 7.3
env:
- DEPS=lowest
- php: 7.1
- php: 7.3
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.2
- php: 7.4
env:
- DEPS=lowest
- php: 7.2
- php: 7.4
env:
- DEPS=latest
- php: 7.3
- php: nightly
env:
- DEPS=lowest
- php: 7.3
- php: nightly
env:
- DEPS=latest

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

install:
- travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
},
"require": {
"php": "^7.1",
"php": "^7.3 || ~8.0.0",
"laminas/laminas-zendframework-bridge": "^1.0",
"mezzio/mezzio-router": "^3.0",
"psr/container": "^1.0",
Expand All @@ -38,9 +38,10 @@
"require-dev": {
"laminas/laminas-coding-standard": "~1.0.0",
"laminas/laminas-diactoros": "^1.7.1",
"malukenho/docheader": "^0.1.6",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^7.0.2"
"malukenho/docheader": "^0.1.8",
"mockery/mockery": "^1.4.2",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.4.2"
},
"autoload": {
"psr-4": {
Expand Down
26 changes: 11 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="mezzio-helpers">
<directory>./test</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="mezzio-helpers">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
20 changes: 19 additions & 1 deletion test/BodyParams/BodyParamsMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
use Mezzio\Helper\Exception\MalformedRequestBodyException;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use ReflectionProperty;
use function fopen;
use function fwrite;
use function get_class;
use function json_encode;

class BodyParamsMiddlewareTest extends TestCase
{
use ProphecyTrait;

/**
* @var Stream
*/
Expand All @@ -38,7 +42,7 @@ class BodyParamsMiddlewareTest extends TestCase
*/
private $bodyParams;

public function setUp()
public function setUp(): void
{
$this->bodyParams = new BodyParamsMiddleware();

Expand Down Expand Up @@ -275,4 +279,18 @@ public function testParsesJsonBodyWhenExpected($method)
$this->assertInstanceOf(Response::class, $result);
$this->assertTrue($handlerTriggered);
}

private function assertAttributeSame($expected, $attribute, $object)
{
$r = new ReflectionProperty($object, $attribute);
$r->setAccessible(true);
self::assertSame($expected, $r->getValue($object));
}

private function assertAttributeContains($expected, $attribute, $object)
{
$r = new ReflectionProperty($object, $attribute);
$r->setAccessible(true);
self::assertContains($expected, $r->getValue($object));
}
}
5 changes: 4 additions & 1 deletion test/BodyParams/FormUrlEncodedStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@

use Mezzio\Helper\BodyParams\FormUrlEncodedStrategy;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;

class FormUrlEncodedStrategyTest extends TestCase
{
use ProphecyTrait;

/**
* @var FormUrlEncodedStrategy
*/
private $strategy;

public function setUp()
public function setUp(): void
{
$this->strategy = new FormUrlEncodedStrategy();
}
Expand Down
5 changes: 4 additions & 1 deletion test/BodyParams/JsonStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
use Mezzio\Helper\BodyParams\JsonStrategy;
use Mezzio\Helper\Exception\MalformedRequestBodyException;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;

class JsonStrategyTest extends TestCase
{
use ProphecyTrait;

/**
* @var JsonStrategy
*/
private $strategy;

public function setUp()
public function setUp(): void
{
$this->strategy = new JsonStrategy();
}
Expand Down
8 changes: 4 additions & 4 deletions test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function setUp() : void
public function testInvocationReturnsArray() : array
{
$config = ($this->provider)();
$this->assertInternalType('array', $config);
$this->assertIsArray($config);

return $config;
}
Expand All @@ -43,14 +43,14 @@ public function testInvocationReturnsArray() : array
public function testReturnedArrayContainsDependencies(array $config) : void
{
$this->assertArrayHasKey('dependencies', $config);
$this->assertInternalType('array', $config['dependencies']);
$this->assertIsArray($config['dependencies']);

$this->assertArrayHasKey('invokables', $config['dependencies']);
$this->assertInternalType('array', $config['dependencies']['invokables']);
$this->assertIsArray($config['dependencies']['invokables']);
$this->assertArrayHasKey(ServerUrlHelper::class, $config['dependencies']['invokables']);

$this->assertArrayHasKey('factories', $config['dependencies']);
$this->assertInternalType('array', $config['dependencies']['factories']);
$this->assertIsArray($config['dependencies']['factories']);
$this->assertArrayHasKey(ServerUrlMiddleware::class, $config['dependencies']['factories']);
$this->assertArrayHasKey(UrlHelper::class, $config['dependencies']['factories']);
$this->assertArrayHasKey(UrlHelperMiddleware::class, $config['dependencies']['factories']);
Expand Down
5 changes: 4 additions & 1 deletion test/ContentLengthMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@

use Mezzio\Helper\ContentLengthMiddleware;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Server\RequestHandlerInterface;

class ContentLengthMiddlewareTest extends TestCase
{
public function setUp()
use ProphecyTrait;

public function setUp(): void
{
$this->response = $response = $this->prophesize(ResponseInterface::class);
$this->request = $request = $this->prophesize(ServerRequestInterface::class)->reveal();
Expand Down
2 changes: 1 addition & 1 deletion test/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function exception() : Generator
*/
public function testExceptionIsInstanceOfExceptionInterface(string $exception) : void
{
self::assertContains('Exception', $exception);
self::assertStringContainsString('Exception', $exception);
self::assertTrue(is_a($exception, ExceptionInterface::class, true));
}
}
3 changes: 3 additions & 0 deletions test/ServerUrlMiddlewareFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
use Mezzio\Helper\ServerUrlMiddleware;
use Mezzio\Helper\ServerUrlMiddlewareFactory;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Container\ContainerInterface;

class ServerUrlMiddlewareFactoryTest extends TestCase
{
use ProphecyTrait;

public function testCreatesAndReturnsMiddlewareWhenHelperIsPresentInContainer()
{
$helper = $this->prophesize(ServerUrlHelper::class);
Expand Down
13 changes: 7 additions & 6 deletions test/ServerUrlMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
use Mezzio\Helper\ServerUrlMiddleware;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UriInterface;
use Psr\Http\Server\RequestHandlerInterface;
use ReflectionProperty;

class ServerUrlMiddlewareTest extends TestCase
{
use ProphecyTrait;

public function testMiddlewareInjectsHelperWithUri()
{
$uri = $this->prophesize(UriInterface::class);
Expand All @@ -44,11 +48,8 @@ public function testMiddlewareInjectsHelperWithUri()
//$this->assertSame($response->reveal(), $test, 'Unexpected return value from middleware');
$this->assertTrue($invoked, 'next() was not invoked');

$this->assertAttributeSame(
$uri->reveal(),
'uri',
$helper,
'Helper was not injected with URI from request'
);
$r = new ReflectionProperty($helper, 'uri');
$r->setAccessible(true);
self::assertSame($uri->reveal(), $r->getValue($helper), 'Helper was not injected with URI from request');
}
}
5 changes: 4 additions & 1 deletion test/Template/RouteTemplateVariableMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
use Mezzio\Router\RouteResult;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class RouteTemplateVariableMiddlewareTest extends TestCase
{
public function setUp()
use ProphecyTrait;

public function setUp(): void
{
$this->request = $this->prophesize(ServerRequestInterface::class);
$this->response = $this->prophesize(ResponseInterface::class);
Expand Down
5 changes: 4 additions & 1 deletion test/Template/TemplateVariableContainerMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
use Mezzio\Helper\Template\TemplateVariableContainerMiddleware;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class TemplateVariableContainerMiddlewareTest extends TestCase
{
public function setUp()
use ProphecyTrait;

public function setUp(): void
{
$this->handler = $this->prophesize(RequestHandlerInterface::class);
$this->request = $this->prophesize(ServerRequestInterface::class);
Expand Down
2 changes: 1 addition & 1 deletion test/Template/TemplateVariableContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class TemplateVariableContainerTest extends TestCase
{
public function setUp()
public function setUp(): void
{
$this->container = new TemplateVariableContainer();
}
Expand Down
13 changes: 12 additions & 1 deletion test/UrlHelperFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
use Mezzio\Helper\UrlHelperFactory;
use Mezzio\Router\RouterInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
use ReflectionProperty;

class UrlHelperFactoryTest extends TestCase
{
use ProphecyTrait;

/**
* @var RouterInterface|ObjectProphecy
*/
Expand All @@ -35,7 +39,7 @@ class UrlHelperFactoryTest extends TestCase
*/
private $factory;

public function setUp()
public function setUp(): void
{
$this->router = $this->prophesize(RouterInterface::class);
$this->container = $this->prophesize(ContainerInterface::class);
Expand Down Expand Up @@ -96,4 +100,11 @@ public function testFactoryAllowsSerialization()
$this->assertAttributeSame('/api', 'basePath', $factory);
$this->assertAttributeSame(Router::class, 'routerServiceName', $factory);
}

private function assertAttributeSame($expected, $attribute, $object)
{
$r = new ReflectionProperty($object, $attribute);
$r->setAccessible(true);
self::assertSame($expected, $r->getValue($object));
}
}
Loading

0 comments on commit d4486ed

Please sign in to comment.