diff --git a/.github/workflows/grumphp.yaml b/.github/workflows/grumphp.yaml index c379c26..e35e5b4 100644 --- a/.github/workflows/grumphp.yaml +++ b/.github/workflows/grumphp.yaml @@ -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 }} @@ -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 @@ -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') }} @@ -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 diff --git a/composer.json b/composer.json index 3ab162d..ce664e2 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 39ae7ee..fca43fb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,12 @@ @@ -10,12 +14,15 @@ - - - src - - - - - + + + src + + + + + + + + diff --git a/test/ApiProblemBundleTest.php b/test/ApiProblemBundleTest.php index de12e13..e675857 100644 --- a/test/ApiProblemBundleTest.php +++ b/test/ApiProblemBundleTest.php @@ -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()); diff --git a/test/DependencyInjection/ApiProblemExtensionTest.php b/test/DependencyInjection/ApiProblemExtensionTest.php index fada960..70c7cd9 100644 --- a/test/DependencyInjection/ApiProblemExtensionTest.php +++ b/test/DependencyInjection/ApiProblemExtensionTest.php @@ -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'; @@ -22,7 +22,7 @@ protected function getContainerExtensions(): array return [new ApiProblemExtension()]; } - /** @test */ + #[Test] public function it_registers_json_exception_listener(): void { $this->load([]); @@ -52,7 +52,7 @@ public function it_registers_json_exception_listener(): void ); } - /** @test */ + #[Test] public function it_contains_exception_transformers(): void { $this->load([]); diff --git a/test/EventListener/JsonApiProblemExceptionListenerTest.php b/test/EventListener/JsonApiProblemExceptionListenerTest.php index fef0e4c..5e2c0bf 100644 --- a/test/EventListener/JsonApiProblemExceptionListenerTest.php +++ b/test/EventListener/JsonApiProblemExceptionListenerTest.php @@ -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; @@ -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; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/test/Exception/ApiProblemHttpExceptionTest.php b/test/Exception/ApiProblemHttpExceptionTest.php index f7ddd77..5228942 100644 --- a/test/Exception/ApiProblemHttpExceptionTest.php +++ b/test/Exception/ApiProblemHttpExceptionTest.php @@ -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; @@ -27,7 +28,7 @@ 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(); @@ -35,7 +36,7 @@ public function it_is_accepted_by_the__api_problem_exception_transformer(): void $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()); @@ -43,7 +44,7 @@ public function it_is_an_instance_of__http_exception(): void $this->assertInstanceOf(HttpException::class, $exception); } - /** @test */ + #[Test] public function it_contains_an_api_problem(): void { $apiProblem = $this->apiProblem->reveal(); @@ -52,7 +53,7 @@ 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()); @@ -60,7 +61,7 @@ public function it_returns_the_correct_http_headers(): void $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()); @@ -68,7 +69,7 @@ public function it_returns_the_correct_default_http_statuscode(): void $this->assertEquals(400, $exception->getStatusCode()); } - /** @test */ + #[Test] public function it_returns_the_correct_specified_http_statuscode(): void { $this->apiProblem->toArray()->willReturn(['status' => 401]); diff --git a/test/Transformer/ApiProblemExceptionTransformerTest.php b/test/Transformer/ApiProblemExceptionTransformerTest.php index 43eced2..b354eb5 100644 --- a/test/Transformer/ApiProblemExceptionTransformerTest.php +++ b/test/Transformer/ApiProblemExceptionTransformerTest.php @@ -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; @@ -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(); @@ -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(); diff --git a/test/Transformer/ChainTest.php b/test/Transformer/ChainTest.php index e5a8545..eb1fc4f 100644 --- a/test/Transformer/ChainTest.php +++ b/test/Transformer/ChainTest.php @@ -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([ @@ -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)]); diff --git a/test/Transformer/HttpExceptionTransformerTest.php b/test/Transformer/HttpExceptionTransformerTest.php index b58fe14..ae37446 100644 --- a/test/Transformer/HttpExceptionTransformerTest.php +++ b/test/Transformer/HttpExceptionTransformerTest.php @@ -9,22 +9,22 @@ use Phpro\ApiProblem\Http\HttpApiProblem; use Phpro\ApiProblemBundle\Transformer\ExceptionTransformerInterface; use Phpro\ApiProblemBundle\Transformer\HttpExceptionTransformer; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\Exception\HttpException; -/** - * @covers \Phpro\ApiProblemBundle\Transformer\HttpExceptionTransformer - */ +#[CoversClass(HttpExceptionTransformer::class)] class HttpExceptionTransformerTest extends TestCase { - /** @test */ + #[Test] public function it_is_an_exception_transformer(): void { $transformer = new HttpExceptionTransformer(); $this->assertInstanceOf(ExceptionTransformerInterface::class, $transformer); } - /** @test */ + #[Test] public function it_accepts_api_problem_exceptions(): void { $transformer = new HttpExceptionTransformer(); @@ -33,7 +33,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 HttpExceptionTransformer(); diff --git a/test/Transformer/SecurityExceptionTransformerTest.php b/test/Transformer/SecurityExceptionTransformerTest.php index 5e81857..046e0f0 100644 --- a/test/Transformer/SecurityExceptionTransformerTest.php +++ b/test/Transformer/SecurityExceptionTransformerTest.php @@ -10,24 +10,24 @@ use Phpro\ApiProblem\Http\UnauthorizedProblem; use Phpro\ApiProblemBundle\Transformer\ExceptionTransformerInterface; use Phpro\ApiProblemBundle\Transformer\SecurityExceptionTransformer; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\RuntimeException; -/** - * @covers \Phpro\ApiProblemBundle\Transformer\SecurityExceptionTransformer - */ +#[CoversClass(SecurityExceptionTransformer::class)] class SecurityExceptionTransformerTest extends TestCase { - /** @test */ + #[Test] public function it_is_an_exception_transformer(): void { $transformer = new SecurityExceptionTransformer(); $this->assertInstanceOf(ExceptionTransformerInterface::class, $transformer); } - /** @test */ + #[Test] public function it_accepts_api_problem_exceptions(): void { $transformer = new SecurityExceptionTransformer(); @@ -36,7 +36,7 @@ public function it_accepts_api_problem_exceptions(): void $this->assertFalse($transformer->accepts(new Exception())); } - /** @test */ + #[Test] public function it_transforms_authentication_exception_to_api_problem(): void { $transformer = new SecurityExceptionTransformer(); @@ -52,7 +52,7 @@ public function it_transforms_authentication_exception_to_api_problem(): void ], $apiProblem->toArray()); } - /** @test */ + #[Test] public function it_transforms_other_security_exceptions_to_api_problem(): void { $transformer = new SecurityExceptionTransformer();