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
47 changes: 47 additions & 0 deletions tests/Fixtures/TestBundle/ApiResource/DeprecationHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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),
];
}
}
44 changes: 44 additions & 0 deletions tests/Functional/DeprecationHeaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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('<https://developer.example.com/deprecation>; rel="deprecation"', $headers['link'][0]);
}
}
Loading