Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/grumphp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.1', '8.2', '8.3', '8.4']
php-versions: ['8.3', '8.4', '8.5']
composer-options: ['', '--prefer-lowest']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }} with ${{ matrix.composer-options }}
Expand All @@ -21,7 +21,7 @@ jobs:
tools: 'composer:v2'
extensions: pcov, mbstring, posix
- name: Set env vars for latest PHP version
if: matrix.php-versions == '8.4'
if: matrix.php-versions == '8.5'
run: |
export COMPOSER_IGNORE_PLATFORM_REQ=php+
export BOX_REQUIREMENT_CHECKER=0
Expand All @@ -34,7 +34,7 @@ jobs:
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -43,5 +43,6 @@ jobs:
run: composer update --prefer-dist --no-progress --ignore-platform-req=php+ ${{ matrix.composer-options }}
- name: Run the tests
run: php vendor/bin/grumphp run --no-interaction
continue-on-error: ${{ matrix.php-versions == '8.5' }}
env:
PHP_CS_FIXER_IGNORE_ENV: 1
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
}
],
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"php": "~8.3.0 || ~8.4.0 || ~8.5.0",
"phpro/api-problem": "^1.0",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.39",
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
"phpro/grumphp-shim": "^2.10",
"phpspec/prophecy-phpunit": "^2.0",
"php-cs-fixer/shim": "^3.88",
"phpro/grumphp-shim": "^2.17",
"phpspec/prophecy": "^1.17",
"phpunit/phpunit": "^9.5",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^12.4",
"symfony/security-core": "^5.4 || ^6.0 || ^7.0"
},
"config": {
Expand Down
25 changes: 16 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
failOnWarning="true"
failOnPhpunitWarning="true"
beStrictAboutOutputDuringTests="true"
>
<testsuites>
<testsuite name="Unit">
<directory>./test</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="var/coverage.xml"/>
</report>
</coverage>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>

<coverage includeUncoveredFiles="true">
<report>
<clover outputFile="var/coverage.xml"/>
</report>
</coverage>
</phpunit>
6 changes: 4 additions & 2 deletions test/ApiProblemBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
namespace PhproTest\ApiProblemBundle;

use Phpro\ApiProblemBundle\ApiProblemBundle;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/** @covers \Phpro\ApiProblemBundle\ApiProblemBundle */
#[CoversClass(ApiProblemBundle::class)]
class ApiProblemBundleTest extends TestCase
{
/** @test */
#[Test]
public function it_is_a_symfony_bundle(): void
{
$this->assertInstanceOf(Bundle::class, new ApiProblemBundle());
Expand Down
10 changes: 5 additions & 5 deletions test/DependencyInjection/ApiProblemExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use Phpro\ApiProblemBundle\DependencyInjection\ApiProblemExtension;
use Phpro\ApiProblemBundle\EventListener\JsonApiProblemExceptionListener;
use Phpro\ApiProblemBundle\Transformer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;

/**
* @covers \Phpro\ApiProblemBundle\DependencyInjection\ApiProblemExtension
*/
#[CoversClass(ApiProblemExtension::class)]
class ApiProblemExtensionTest extends AbstractExtensionTestCase
{
private const TRANSFORMER_TAG = 'phpro.api_problem.exception_transformer';
Expand All @@ -22,7 +22,7 @@ protected function getContainerExtensions(): array
return [new ApiProblemExtension()];
}

/** @test */
#[Test]
public function it_registers_json_exception_listener(): void
{
$this->load([]);
Expand Down Expand Up @@ -52,7 +52,7 @@ public function it_registers_json_exception_listener(): void
);
}

/** @test */
#[Test]
public function it_contains_exception_transformers(): void
{
$this->load([]);
Expand Down
20 changes: 11 additions & 9 deletions test/EventListener/JsonApiProblemExceptionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Phpro\ApiProblem\Http\HttpApiProblem;
use Phpro\ApiProblemBundle\EventListener\JsonApiProblemExceptionListener;
use Phpro\ApiProblemBundle\Transformer\ExceptionTransformerInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand All @@ -22,7 +24,7 @@
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/** @covers \Phpro\ApiProblemBundle\EventListener\JsonApiProblemExceptionListener */
#[CoversClass(JsonApiProblemExceptionListener::class)]
class JsonApiProblemExceptionListenerTest extends TestCase
{
use ProphecyTrait;
Expand All @@ -38,7 +40,7 @@ protected function setUp(): void
$this->exceptionTransformer->accepts(Argument::any())->willReturn(false);
}

/** @test */
#[Test]
public function it_does_nothing_on_non_json_requests(): void
{
$listener = new JsonApiProblemExceptionListener($this->exceptionTransformer->reveal(), false);
Expand All @@ -53,7 +55,7 @@ public function it_does_nothing_on_non_json_requests(): void
$this->assertNull($event->getResponse());
}

/** @test */
#[Test]
public function it_runs_on_json_route_formats(): void
{
$listener = new JsonApiProblemExceptionListener($this->exceptionTransformer->reveal(), false);
Expand All @@ -69,7 +71,7 @@ public function it_runs_on_json_route_formats(): void
$this->assertApiProblemWithResponseBody($event, 500, $this->parseDataForException($exception));
}

/** @test */
#[Test]
public function it_runs_on_json_content_types(): void
{
$listener = new JsonApiProblemExceptionListener($this->exceptionTransformer->reveal(), false);
Expand All @@ -84,7 +86,7 @@ public function it_runs_on_json_content_types(): void
$this->assertApiProblemWithResponseBody($event, 500, $this->parseDataForException($exception));
}

/** @test */
#[Test]
public function it_runs_on_json_accept_header(): void
{
$listener = new JsonApiProblemExceptionListener($this->exceptionTransformer->reveal(), false);
Expand All @@ -99,7 +101,7 @@ public function it_runs_on_json_accept_header(): void
$this->assertApiProblemWithResponseBody($event, 500, $this->parseDataForException($exception));
}

/** @test */
#[Test]
public function it_parses_an_api_problem_response(): void
{
$listener = new JsonApiProblemExceptionListener($this->exceptionTransformer->reveal(), false);
Expand All @@ -114,7 +116,7 @@ public function it_parses_an_api_problem_response(): void
$this->assertApiProblemWithResponseBody($event, 500, $this->parseDataForException($exception));
}

/** @test */
#[Test]
public function it_uses_an_exception_transformer(): void
{
$listener = new JsonApiProblemExceptionListener($this->exceptionTransformer->reveal(), false);
Expand All @@ -134,7 +136,7 @@ public function it_uses_an_exception_transformer(): void
$this->assertApiProblemWithResponseBody($event, 400, []);
}

/** @test */
#[Test]
public function it_returns_the_status_code_from_the_api_problem(): void
{
$listener = new JsonApiProblemExceptionListener($this->exceptionTransformer->reveal(), false);
Expand All @@ -154,7 +156,7 @@ public function it_returns_the_status_code_from_the_api_problem(): void
$this->assertApiProblemWithResponseBody($event, 123, ['status' => 123]);
}

/** @test */
#[Test]
public function it_parses_a_debuggable_api_problem_response(): void
{
$listener = new JsonApiProblemExceptionListener($this->exceptionTransformer->reveal(), true);
Expand Down
13 changes: 7 additions & 6 deletions test/Exception/ApiProblemHttpExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Phpro\ApiProblem\Http\HttpApiProblem;
use Phpro\ApiProblemBundle\Exception\ApiProblemHttpException;
use Phpro\ApiProblemBundle\Transformer\ApiProblemExceptionTransformer;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
Expand All @@ -27,23 +28,23 @@ protected function setUp(): void/* The :void return type declaration that should
$this->apiProblem->toArray()->willReturn([]);
}

/** @test */
#[Test]
public function it_is_accepted_by_the__api_problem_exception_transformer(): void
{
$transformer = new ApiProblemExceptionTransformer();

$this->assertTrue($transformer->accepts(new ApiProblemHttpException($this->apiProblem->reveal())));
}

/** @test */
#[Test]
public function it_is_an_instance_of__http_exception(): void
{
$exception = new ApiProblemHttpException($this->apiProblem->reveal());

$this->assertInstanceOf(HttpException::class, $exception);
}

/** @test */
#[Test]
public function it_contains_an_api_problem(): void
{
$apiProblem = $this->apiProblem->reveal();
Expand All @@ -52,23 +53,23 @@ public function it_contains_an_api_problem(): void
$this->assertEquals($apiProblem, $exception->getApiProblem());
}

/** @test */
#[Test]
public function it_returns_the_correct_http_headers(): void
{
$exception = new ApiProblemHttpException($this->apiProblem->reveal());

$this->assertEquals(['Content-Type' => 'application/problem+json'], $exception->getHeaders());
}

/** @test */
#[Test]
public function it_returns_the_correct_default_http_statuscode(): void
{
$exception = new ApiProblemHttpException($this->apiProblem->reveal());

$this->assertEquals(400, $exception->getStatusCode());
}

/** @test */
#[Test]
public function it_returns_the_correct_specified_http_statuscode(): void
{
$this->apiProblem->toArray()->willReturn(['status' => 401]);
Expand Down
12 changes: 6 additions & 6 deletions test/Transformer/ApiProblemExceptionTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
use Phpro\ApiProblem\Exception\ApiProblemException;
use Phpro\ApiProblemBundle\Transformer\ApiProblemExceptionTransformer;
use Phpro\ApiProblemBundle\Transformer\ExceptionTransformerInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;

/**
* @covers \Phpro\ApiProblemBundle\Transformer\ApiProblemExceptionTransformer
*/
#[CoversClass(ApiProblemExceptionTransformer::class)]
class ApiProblemExceptionTransformerTest extends TestCase
{
use ProphecyTrait;
Expand All @@ -31,14 +31,14 @@ protected function setUp(): void/* The :void return type declaration that should
$this->apiProblem->toArray()->willReturn([]);
}

/** @test */
#[Test]
public function it_is_an_exception_transformer(): void
{
$transformer = new ApiProblemExceptionTransformer();
$this->assertInstanceOf(ExceptionTransformerInterface::class, $transformer);
}

/** @test */
#[Test]
public function it_accepts_api_problem_exceptions(): void
{
$transformer = new ApiProblemExceptionTransformer();
Expand All @@ -47,7 +47,7 @@ public function it_accepts_api_problem_exceptions(): void
$this->assertFalse($transformer->accepts(new Exception()));
}

/** @test */
#[Test]
public function it_transforms_exception_to_api_problem(): void
{
$transformer = new ApiProblemExceptionTransformer();
Expand Down
14 changes: 7 additions & 7 deletions test/Transformer/ChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@
use Phpro\ApiProblem\Http\ExceptionApiProblem;
use Phpro\ApiProblemBundle\Transformer\Chain;
use Phpro\ApiProblemBundle\Transformer\ExceptionTransformerInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;

/**
* @covers \Phpro\ApiProblemBundle\Transformer\Chain
*/
#[CoversClass(Chain::class)]
class ChainTest extends TestCase
{
use ProphecyTrait;

/** @test */
#[Test]
public function it_is_an_exception_transformer(): void
{
$transformer = new Chain([]);
$this->assertInstanceOf(ExceptionTransformerInterface::class, $transformer);
}

/** @test */
#[Test]
public function it_accepts_any_exception(): void
{
$transformer = new Chain([]);
$this->assertTrue($transformer->accepts(new Exception()));
}

/** @test */
#[Test]
public function it_transforms_with_first_acceptable_transformer(): void
{
$transformer = new Chain([
Expand All @@ -47,7 +47,7 @@ public function it_transforms_with_first_acceptable_transformer(): void
$this->assertEquals($apiProblem1, $transformer->transform(new Exception()));
}

/** @test */
#[Test]
public function it_transforms_to_basic_exception_problem_when_no_transformer_matches(): void
{
$transformer = new Chain([$this->mockTransformer(false)]);
Expand Down
Loading
Loading