diff --git a/tests/Fixtures/TestBundle/ApiResource/DeprecationHeader.php b/tests/Fixtures/TestBundle/ApiResource/DeprecationHeader.php new file mode 100644 index 0000000000..fd114a5ddb --- /dev/null +++ b/tests/Fixtures/TestBundle/ApiResource/DeprecationHeader.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\GetCollection; +use Symfony\Component\WebLink\Link; + +#[ApiResource( + operations: [new GetCollection( + headers: [ + 'deprecation' => '@1688169599', + 'sunset' => 'Sun, 30 Jun 2024 23:59:59 UTC', + ], + links: [ + new Link('deprecation', 'https://developer.example.com/deprecation'), + ], + deprecationReason: 'This API is deprecated', + provider: [self::class, 'provide'], + )], +)] +class DeprecationHeader +{ + public function __construct(#[ApiProperty(identifier: true)] public int $id) + { + } + + public static function provide(): iterable + { + return [ + new self(1), + new self(2), + ]; + } +} diff --git a/tests/Functional/DeprecationHeaderTest.php b/tests/Functional/DeprecationHeaderTest.php new file mode 100644 index 0000000000..bdebfe481e --- /dev/null +++ b/tests/Functional/DeprecationHeaderTest.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Tests\Functional; + +use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\DeprecationHeader; +use ApiPlatform\Tests\SetupClassResourcesTrait; + +final class DeprecationHeaderTest extends ApiTestCase +{ + use SetupClassResourcesTrait; + + protected static ?bool $alwaysBootKernel = false; + + /** + * @return class-string[] + */ + public static function getResources(): array + { + return [DeprecationHeader::class]; + } + + public function testDeprecationHeader(): void + { + $response = self::createClient()->request('GET', '/deprecation_headers'); + + $headers = $response->getHeaders(); + + $this->assertContains('@1688169599', $headers['deprecation']); + $this->assertContains('Sun, 30 Jun 2024 23:59:59 UTC', $headers['sunset']); + $this->assertStringContainsString('; rel="deprecation"', $headers['link'][0]); + } +}