Skip to content

Commit 11ca7d3

Browse files
authored
test: web links and deprecation header (#7582)
1 parent e64b93e commit 11ca7d3

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource;
15+
16+
use ApiPlatform\Metadata\ApiProperty;
17+
use ApiPlatform\Metadata\ApiResource;
18+
use ApiPlatform\Metadata\GetCollection;
19+
use Symfony\Component\WebLink\Link;
20+
21+
#[ApiResource(
22+
operations: [new GetCollection(
23+
headers: [
24+
'deprecation' => '@1688169599',
25+
'sunset' => 'Sun, 30 Jun 2024 23:59:59 UTC',
26+
],
27+
links: [
28+
new Link('deprecation', 'https://developer.example.com/deprecation'),
29+
],
30+
deprecationReason: 'This API is deprecated',
31+
provider: [self::class, 'provide'],
32+
)],
33+
)]
34+
class DeprecationHeader
35+
{
36+
public function __construct(#[ApiProperty(identifier: true)] public int $id)
37+
{
38+
}
39+
40+
public static function provide(): iterable
41+
{
42+
return [
43+
new self(1),
44+
new self(2),
45+
];
46+
}
47+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Functional;
15+
16+
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
17+
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\DeprecationHeader;
18+
use ApiPlatform\Tests\SetupClassResourcesTrait;
19+
20+
final class DeprecationHeaderTest extends ApiTestCase
21+
{
22+
use SetupClassResourcesTrait;
23+
24+
protected static ?bool $alwaysBootKernel = false;
25+
26+
/**
27+
* @return class-string[]
28+
*/
29+
public static function getResources(): array
30+
{
31+
return [DeprecationHeader::class];
32+
}
33+
34+
public function testDeprecationHeader(): void
35+
{
36+
$response = self::createClient()->request('GET', '/deprecation_headers');
37+
38+
$headers = $response->getHeaders();
39+
40+
$this->assertContains('@1688169599', $headers['deprecation']);
41+
$this->assertContains('Sun, 30 Jun 2024 23:59:59 UTC', $headers['sunset']);
42+
$this->assertStringContainsString('<https://developer.example.com/deprecation>; rel="deprecation"', $headers['link'][0]);
43+
}
44+
}

0 commit comments

Comments
 (0)