Skip to content

Commit

Permalink
Merge pull request #21 from snapshotpl/php-8.1
Browse files Browse the repository at this point in the history
Support for PHP 8.1
  • Loading branch information
Ocramius authored Dec 9, 2021
2 parents 5d57431 + a79609b commit dc94f12
Show file tree
Hide file tree
Showing 29 changed files with 203 additions and 150 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
}
},
"require": {
"php": "^7.3 || ~8.0.0",
"php": "^7.3 || ~8.0.0 || ~8.1.0",
"ext-json": "*",
"laminas/laminas-eventmanager": "^2.6.3 || ^3.0.1",
"laminas/laminas-http": "^2.5.4",
"laminas/laminas-http": "^2.15.1",
"laminas/laminas-json": "^2.6.1 || ^3.0",
"laminas/laminas-mvc": "^2.7.15 || ^3.0.4",
"laminas/laminas-view": "^2.8.1",
"laminas/laminas-zendframework-bridge": "^1.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "~2.2.0",
"laminas/laminas-coding-standard": "~2.3.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3",
"psalm/plugin-phpunit": "^0.16.0",
Expand Down
265 changes: 128 additions & 137 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem;

return [
Expand Down
6 changes: 4 additions & 2 deletions src/ApiProblem.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem;

use Exception;
Expand Down Expand Up @@ -136,7 +138,7 @@ class ApiProblem
* if the status matches any known, the title field will be selected
* from $problemStatusTitles as a result.
*
* @param int $status
* @param int|string $status
* @param string|Exception|Throwable $detail
* @param string $type
* @param string $title
Expand Down Expand Up @@ -165,7 +167,7 @@ public function __construct($status, $detail, $type = null, $title = null, array
$status = 500;
}

$this->status = $status;
$this->status = (int) $status;
$this->detail = $detail;
$this->title = $title;

Expand Down
7 changes: 6 additions & 1 deletion src/ApiProblemResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem;

use Laminas\Http\Headers;
Expand Down Expand Up @@ -29,7 +31,10 @@ public function __construct(ApiProblem $apiProblem)
{
$this->apiProblem = $apiProblem;
$this->setCustomStatusCode($apiProblem->status);
$this->setReasonPhrase($apiProblem->title);

if ($apiProblem->title !== null) {
$this->setReasonPhrase($apiProblem->title);
}

$this->jsonFlags = JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/DomainException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Exception;

class DomainException extends \DomainException implements
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Exception;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Exception;

class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/ProblemExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Exception;

use Traversable;
Expand Down
2 changes: 2 additions & 0 deletions src/Factory/ApiProblemListenerFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Factory;

use Interop\Container\ContainerInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Factory/ApiProblemRendererFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Factory;

use Interop\Container\ContainerInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Factory/ApiProblemStrategyFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Factory;

use Interop\Container\ContainerInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Factory/RenderErrorListenerFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Factory;

use Interop\Container\ContainerInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Factory/SendApiProblemResponseListenerFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Factory;

use Interop\Container\ContainerInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Listener/ApiProblemListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Listener;

use Exception;
Expand Down
2 changes: 2 additions & 0 deletions src/Listener/RenderErrorListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Listener;

use Exception;
Expand Down
2 changes: 2 additions & 0 deletions src/Listener/SendApiProblemResponseListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\Listener;

use Laminas\ApiTools\ApiProblem\ApiProblemResponse;
Expand Down
2 changes: 2 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem;

use Laminas\ApiTools\ApiProblem\Listener\SendApiProblemResponseListener;
Expand Down
2 changes: 2 additions & 0 deletions src/View/ApiProblemModel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\View;

use Laminas\ApiTools\ApiProblem\ApiProblem;
Expand Down
2 changes: 2 additions & 0 deletions src/View/ApiProblemRenderer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\View;

use Laminas\View\Model\ModelInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/View/ApiProblemStrategy.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem\View;

use Laminas\ApiTools\ApiProblem\ApiProblem;
Expand Down
19 changes: 13 additions & 6 deletions test/ApiProblemResponseTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

declare(strict_types=1);

namespace LaminasTest\ApiTools\ApiProblem;

use Laminas\ApiTools\ApiProblem\ApiProblem;
use Laminas\ApiTools\ApiProblem\ApiProblemResponse;
use Laminas\ApiTools\ApiProblem\Exception\DomainException;
use Laminas\Http\Header\ContentType;
use Laminas\Http\Response;
use PHPUnit\Framework\TestCase;
Expand All @@ -20,9 +23,6 @@ public function testApiProblemResponseIsAnHttpResponse(): void
$this->assertInstanceOf(Response::class, $response);
}

/**
* @depends testApiProblemResponseIsAnHttpResponse
*/
public function testApiProblemResponseSetsStatusCodeAndReasonPhrase(): void
{
$response = new ApiProblemResponse(new ApiProblem(400, 'Random error'));
Expand All @@ -32,6 +32,16 @@ public function testApiProblemResponseSetsStatusCodeAndReasonPhrase(): void
$this->assertEquals('bad request', strtolower($response->getReasonPhrase()));
}

public function testApiProblemResponseSetsStatusCodeAndReasonPhraseUsingException(): void
{
$exception = new DomainException('Random error', 400);
$response = new ApiProblemResponse(new ApiProblem(400, $exception));
$this->assertEquals(400, $response->getStatusCode());
$this->assertIsString($response->getReasonPhrase());
$this->assertNotEmpty($response->getReasonPhrase());
$this->assertEquals('bad request', strtolower($response->getReasonPhrase()));
}

public function testApiProblemResponseBodyIsSerializedApiProblem(): void
{
$additional = [
Expand All @@ -51,9 +61,6 @@ public function testApiProblemResponseBodyIsSerializedApiProblem(): void
$this->assertEquals($expected, json_decode($response->getContent(), true));
}

/**
* @depends testApiProblemResponseIsAnHttpResponse
*/
public function testApiProblemResponseSetsContentTypeHeader(): void
{
$response = new ApiProblemResponse(new ApiProblem(400, 'Random error'));
Expand Down
4 changes: 3 additions & 1 deletion test/ApiProblemTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace LaminasTest\ApiTools\ApiProblem;

use Laminas\ApiTools\ApiProblem\ApiProblem;
Expand Down Expand Up @@ -94,7 +96,7 @@ public function testExceptionsCanTriggerInclusionOfStackTraceInDetails(): void
public function testExceptionsCanTriggerInclusionOfNestedExceptions(): void
{
$exceptionChild = new \Exception('child exception');
$exceptionParent = new \Exception('parent exception', null, $exceptionChild);
$exceptionParent = new \Exception('parent exception', 0, $exceptionChild);

$apiProblem = new ApiProblem('500', $exceptionParent);
$apiProblem->setDetailIncludesStackTrace(true);
Expand Down
2 changes: 2 additions & 0 deletions test/Listener/ApiProblemListenerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace LaminasTest\ApiTools\ApiProblem\Listener;

use Laminas\ApiTools\ApiProblem\ApiProblem;
Expand Down
2 changes: 2 additions & 0 deletions test/Listener/RenderErrorListenerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace LaminasTest\ApiTools\ApiProblem\Listener;

use Laminas\ApiTools\ApiProblem\ApiProblem;
Expand Down
2 changes: 2 additions & 0 deletions test/Listener/SendApiProblemResponseListenerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace LaminasTest\ApiTools\ApiProblem\Listener;

use Laminas\ApiTools\ApiProblem\ApiProblem;
Expand Down
2 changes: 2 additions & 0 deletions test/ModuleTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Laminas\ApiTools\ApiProblem;

use Laminas\ApiTools\ApiProblem\Listener\ApiProblemListener;
Expand Down
2 changes: 2 additions & 0 deletions test/View/ApiProblemRendererTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace LaminasTest\ApiTools\ApiProblem\View;

use Exception;
Expand Down
2 changes: 2 additions & 0 deletions test/View/ApiProblemStrategyTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace LaminasTest\ApiTools\ApiProblem\View;

use Laminas\ApiTools\ApiProblem\ApiProblem;
Expand Down

0 comments on commit dc94f12

Please sign in to comment.