mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-13 04:59:24 +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;
|
namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;
|
||||||
|
|
||||||
|
use Nelmio\ApiDocBundle\Annotation\Areas;
|
||||||
use Nelmio\ApiDocBundle\Annotation\Model;
|
use Nelmio\ApiDocBundle\Annotation\Model;
|
||||||
|
use Nelmio\ApiDocBundle\Annotation\Security;
|
||||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\Article;
|
use Nelmio\ApiDocBundle\Tests\Functional\Entity\Article;
|
||||||
use OpenApi\Annotations as OA;
|
use OpenApi\Annotations as OA;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
@ -33,4 +35,19 @@ class ApiController81 extends ApiController80
|
|||||||
public function fetchArticleActionWithAttributes()
|
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));
|
], 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 = [
|
$expected = [
|
||||||
['api_key' => []],
|
['api_key' => []],
|
||||||
@ -357,6 +360,15 @@ class FunctionalTest extends WebTestCase
|
|||||||
$this->assertEquals($expected, $operation->security);
|
$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()
|
public function testClassSecurityAction()
|
||||||
{
|
{
|
||||||
$operation = $this->getOperation('/api/security/class', 'get');
|
$operation = $this->getOperation('/api/security/class', 'get');
|
||||||
|
@ -157,9 +157,9 @@ class FilteredRouteCollectionBuilderTest extends TestCase
|
|||||||
$this->assertCount(1, $filteredRoutes);
|
$this->assertCount(1, $filteredRoutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMatchingRoutes(): array
|
public function getMatchingRoutes(): iterable
|
||||||
{
|
{
|
||||||
return [
|
yield from [
|
||||||
['r1', new Route('/api/bar/action1')],
|
['r1', new Route('/api/bar/action1')],
|
||||||
['r2', new Route('/api/foo/action1'), ['path_patterns' => ['^/api', 'i/fo', 'n1$']]],
|
['r2', new Route('/api/foo/action1'), ['path_patterns' => ['^/api', 'i/fo', 'n1$']]],
|
||||||
['r3', new Route('/api/foo/action2'), ['path_patterns' => ['^/api/foo/action2$']]],
|
['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']]],
|
['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']]],
|
['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);
|
$this->assertCount(1, $filteredRoutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMatchingRoutesWithAnnotation(): array
|
public function getMatchingRoutesWithAnnotation(): iterable
|
||||||
{
|
{
|
||||||
return [
|
yield from [
|
||||||
'with annotation only' => [
|
'with annotation only' => [
|
||||||
'r10',
|
'r10',
|
||||||
new Route('/api/areas/new', ['_controller' => 'ApiController::newAreaAction']),
|
new Route('/api/areas/new', ['_controller' => 'ApiController::newAreaAction']),
|
||||||
@ -215,6 +219,21 @@ class FilteredRouteCollectionBuilderTest extends TestCase
|
|||||||
['path_patterns' => ['^/api'], 'with_annotation' => true],
|
['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