mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
Test more PHP 8.1 attributes support (#1936)
* Test `@Areas` as a php 8.1 attribute * Test `@Security` as PHP 8.1 attribute
This commit is contained in:
parent
cc97b0ba45
commit
ced932b8e7
@ -11,7 +11,9 @@
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;
|
||||
|
||||
use Nelmio\ApiDocBundle\Annotation\Areas;
|
||||
use Nelmio\ApiDocBundle\Annotation\Model;
|
||||
use Nelmio\ApiDocBundle\Annotation\Security;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\Article;
|
||||
use OpenApi\Annotations as OA;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
@ -33,4 +35,19 @@ class ApiController81 extends ApiController80
|
||||
public function fetchArticleActionWithAttributes()
|
||||
{
|
||||
}
|
||||
|
||||
#[Areas(['area', 'area2'])]
|
||||
#[Route('/areas_attributes/new', methods: ['GET', 'POST'])]
|
||||
public function newAreaActionAttributes()
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/security_attributes')]
|
||||
#[OA\Response(response: '201', description: '')]
|
||||
#[Security(name: 'api_key')]
|
||||
#[Security(name: 'basic')]
|
||||
#[Security(name: 'oauth2', scopes: ['scope_1'])]
|
||||
public function securityActionAttributes()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -345,9 +345,12 @@ class FunctionalTest extends WebTestCase
|
||||
], json_decode($this->getModel('DummyType')->toJson(), true));
|
||||
}
|
||||
|
||||
public function testSecurityAction()
|
||||
/**
|
||||
* @dataProvider provideSecurityRoute
|
||||
*/
|
||||
public function testSecurityAction(string $route)
|
||||
{
|
||||
$operation = $this->getOperation('/api/security', 'get');
|
||||
$operation = $this->getOperation($route, 'get');
|
||||
|
||||
$expected = [
|
||||
['api_key' => []],
|
||||
@ -357,6 +360,15 @@ class FunctionalTest extends WebTestCase
|
||||
$this->assertEquals($expected, $operation->security);
|
||||
}
|
||||
|
||||
public function provideSecurityRoute(): iterable
|
||||
{
|
||||
yield 'Annotations' => ['/api/security'];
|
||||
|
||||
if (\PHP_VERSION_ID >= 80100) {
|
||||
yield 'Attributes' => ['/api/security_attributes'];
|
||||
}
|
||||
}
|
||||
|
||||
public function testClassSecurityAction()
|
||||
{
|
||||
$operation = $this->getOperation('/api/security/class', 'get');
|
||||
|
@ -157,9 +157,9 @@ class FilteredRouteCollectionBuilderTest extends TestCase
|
||||
$this->assertCount(1, $filteredRoutes);
|
||||
}
|
||||
|
||||
public function getMatchingRoutes(): array
|
||||
public function getMatchingRoutes(): iterable
|
||||
{
|
||||
return [
|
||||
yield from [
|
||||
['r1', new Route('/api/bar/action1')],
|
||||
['r2', new Route('/api/foo/action1'), ['path_patterns' => ['^/api', 'i/fo', 'n1$']]],
|
||||
['r3', new Route('/api/foo/action2'), ['path_patterns' => ['^/api/foo/action2$']]],
|
||||
@ -167,6 +167,10 @@ class FilteredRouteCollectionBuilderTest extends TestCase
|
||||
['r9', new Route('/api/bar/action1', [], [], [], 'api.example.com'), ['path_patterns' => ['^/api/'], 'host_patterns' => ['^api\.ex']]],
|
||||
['r10', new Route('/api/areas/new'), ['path_patterns' => ['^/api']]],
|
||||
];
|
||||
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
yield ['r10', new Route('/api/areas_attributes/new'), ['path_patterns' => ['^/api']]];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,9 +205,9 @@ class FilteredRouteCollectionBuilderTest extends TestCase
|
||||
$this->assertCount(1, $filteredRoutes);
|
||||
}
|
||||
|
||||
public function getMatchingRoutesWithAnnotation(): array
|
||||
public function getMatchingRoutesWithAnnotation(): iterable
|
||||
{
|
||||
return [
|
||||
yield from [
|
||||
'with annotation only' => [
|
||||
'r10',
|
||||
new Route('/api/areas/new', ['_controller' => 'ApiController::newAreaAction']),
|
||||
@ -215,6 +219,21 @@ class FilteredRouteCollectionBuilderTest extends TestCase
|
||||
['path_patterns' => ['^/api'], 'with_annotation' => true],
|
||||
],
|
||||
];
|
||||
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
yield from [
|
||||
'with attribute only' => [
|
||||
'r10',
|
||||
new Route('/api/areas_attributes/new', ['_controller' => 'ApiController::newAreaActionAttributes']),
|
||||
['with_annotation' => true],
|
||||
],
|
||||
'with attribute and path patterns' => [
|
||||
'r10',
|
||||
new Route('/api/areas_attributes/new', ['_controller' => 'ApiController::newAreaActionAttributes']),
|
||||
['path_patterns' => ['^/api'], 'with_annotation' => true],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user