diff --git a/.gitignore b/.gitignore index d5e33e7..ad7b1cf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /coveralls-upload.json /phpunit.xml /vendor/ +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml index d4cffa2..00a4f8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,30 +6,30 @@ 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 @@ -37,7 +37,7 @@ 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 diff --git a/composer.json b/composer.json index 4711509..f0d7a05 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 020be81..4fcfeb2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,17 +1,13 @@ - - - - ./test - - - - - - src - - + + + + src + + + + + ./test + + diff --git a/test/BodyParams/BodyParamsMiddlewareTest.php b/test/BodyParams/BodyParamsMiddlewareTest.php index 2b0d1c4..4687f4c 100644 --- a/test/BodyParams/BodyParamsMiddlewareTest.php +++ b/test/BodyParams/BodyParamsMiddlewareTest.php @@ -18,9 +18,11 @@ 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; @@ -28,6 +30,8 @@ class BodyParamsMiddlewareTest extends TestCase { + use ProphecyTrait; + /** * @var Stream */ @@ -38,7 +42,7 @@ class BodyParamsMiddlewareTest extends TestCase */ private $bodyParams; - public function setUp() + public function setUp(): void { $this->bodyParams = new BodyParamsMiddleware(); @@ -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)); + } } diff --git a/test/BodyParams/FormUrlEncodedStrategyTest.php b/test/BodyParams/FormUrlEncodedStrategyTest.php index 57a6e2b..699f869 100644 --- a/test/BodyParams/FormUrlEncodedStrategyTest.php +++ b/test/BodyParams/FormUrlEncodedStrategyTest.php @@ -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(); } diff --git a/test/BodyParams/JsonStrategyTest.php b/test/BodyParams/JsonStrategyTest.php index 232d4be..7af96dd 100644 --- a/test/BodyParams/JsonStrategyTest.php +++ b/test/BodyParams/JsonStrategyTest.php @@ -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(); } diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 2e42e59..ca64287 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -32,7 +32,7 @@ protected function setUp() : void public function testInvocationReturnsArray() : array { $config = ($this->provider)(); - $this->assertInternalType('array', $config); + $this->assertIsArray($config); return $config; } @@ -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']); diff --git a/test/ContentLengthMiddlewareTest.php b/test/ContentLengthMiddlewareTest.php index effe0bb..b878d25 100644 --- a/test/ContentLengthMiddlewareTest.php +++ b/test/ContentLengthMiddlewareTest.php @@ -12,6 +12,7 @@ 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; @@ -19,7 +20,9 @@ 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(); diff --git a/test/ExceptionTest.php b/test/ExceptionTest.php index 16ca93f..b0c1c9a 100644 --- a/test/ExceptionTest.php +++ b/test/ExceptionTest.php @@ -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)); } } diff --git a/test/ServerUrlMiddlewareFactoryTest.php b/test/ServerUrlMiddlewareFactoryTest.php index 5ba6a80..7747689 100644 --- a/test/ServerUrlMiddlewareFactoryTest.php +++ b/test/ServerUrlMiddlewareFactoryTest.php @@ -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); diff --git a/test/ServerUrlMiddlewareTest.php b/test/ServerUrlMiddlewareTest.php index e481b77..9f2ca44 100644 --- a/test/ServerUrlMiddlewareTest.php +++ b/test/ServerUrlMiddlewareTest.php @@ -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); @@ -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'); } } diff --git a/test/Template/RouteTemplateVariableMiddlewareTest.php b/test/Template/RouteTemplateVariableMiddlewareTest.php index 736aeb6..9374fbf 100644 --- a/test/Template/RouteTemplateVariableMiddlewareTest.php +++ b/test/Template/RouteTemplateVariableMiddlewareTest.php @@ -16,6 +16,7 @@ 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; @@ -23,7 +24,9 @@ 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); diff --git a/test/Template/TemplateVariableContainerMiddlewareTest.php b/test/Template/TemplateVariableContainerMiddlewareTest.php index fb59467..bab79ed 100644 --- a/test/Template/TemplateVariableContainerMiddlewareTest.php +++ b/test/Template/TemplateVariableContainerMiddlewareTest.php @@ -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); diff --git a/test/Template/TemplateVariableContainerTest.php b/test/Template/TemplateVariableContainerTest.php index 97428e5..60c77e3 100644 --- a/test/Template/TemplateVariableContainerTest.php +++ b/test/Template/TemplateVariableContainerTest.php @@ -15,7 +15,7 @@ class TemplateVariableContainerTest extends TestCase { - public function setUp() + public function setUp(): void { $this->container = new TemplateVariableContainer(); } diff --git a/test/UrlHelperFactoryTest.php b/test/UrlHelperFactoryTest.php index c65318f..38655f5 100644 --- a/test/UrlHelperFactoryTest.php +++ b/test/UrlHelperFactoryTest.php @@ -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 */ @@ -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); @@ -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)); + } } diff --git a/test/UrlHelperMiddlewareFactoryTest.php b/test/UrlHelperMiddlewareFactoryTest.php index 7d805db..ebcfec0 100644 --- a/test/UrlHelperMiddlewareFactoryTest.php +++ b/test/UrlHelperMiddlewareFactoryTest.php @@ -15,17 +15,21 @@ use Mezzio\Helper\UrlHelperMiddleware; use Mezzio\Helper\UrlHelperMiddlewareFactory; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; +use ReflectionProperty; class UrlHelperMiddlewareFactoryTest extends TestCase { + use ProphecyTrait; + /** * @var ContainerInterface|ObjectProphecy */ private $container; - public function setUp() + public function setUp(): void { $this->container = $this->prophesize(ContainerInterface::class); } @@ -78,4 +82,11 @@ public function testFactoryAllowsSerialization() $this->assertInstanceOf(UrlHelperMiddlewareFactory::class, $factory); $this->assertAttributeSame(MyUrlHelper::class, 'urlHelperServiceName', $factory); } + + private function assertAttributeSame($expected, $attribute, $object) + { + $r = new ReflectionProperty($object, $attribute); + $r->setAccessible(true); + self::assertSame($expected, $r->getValue($object)); + } } diff --git a/test/UrlHelperMiddlewareTest.php b/test/UrlHelperMiddlewareTest.php index 3a0ff34..3d2f5d1 100644 --- a/test/UrlHelperMiddlewareTest.php +++ b/test/UrlHelperMiddlewareTest.php @@ -15,6 +15,7 @@ use Mezzio\Router\RouteResult; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -22,12 +23,14 @@ class UrlHelperMiddlewareTest extends TestCase { + use ProphecyTrait; + /** * @var UrlHelper|ObjectProphecy */ private $helper; - public function setUp() + public function setUp(): void { $this->helper = $this->prophesize(UrlHelper::class); } diff --git a/test/UrlHelperTest.php b/test/UrlHelperTest.php index 9a9ae42..7b82107 100644 --- a/test/UrlHelperTest.php +++ b/test/UrlHelperTest.php @@ -19,12 +19,16 @@ use Mockery; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; +use ReflectionProperty; use stdClass; use TypeError; class UrlHelperTest extends TestCase { + use ProphecyTrait; + use MockeryPHPUnitIntegration; /** @@ -32,7 +36,7 @@ class UrlHelperTest extends TestCase */ private $router; - public function setUp() + public function setUp(): void { $this->router = $this->prophesize(RouterInterface::class); } @@ -393,4 +397,18 @@ public function testGetRouteResultWithRouteResultSet() $helper->setRouteResult($result->reveal()); $this->assertInstanceOf(RouteResult::class, $helper->getRouteResult()); } + + private function assertAttributeSame($expected, $attribute, $object) + { + $r = new ReflectionProperty($object, $attribute); + $r->setAccessible(true); + self::assertSame($expected, $r->getValue($object)); + } + + private function assertAttributeEquals($expected, $attribute, $object) + { + $r = new ReflectionProperty($object, $attribute); + $r->setAccessible(true); + self::assertEquals($expected, $r->getValue($object)); + } }