Skip to content

Commit

Permalink
cleanup old php & symfony version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Jan 18, 2025
1 parent 80ef0f5 commit 367d892
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 211 deletions.
5 changes: 0 additions & 5 deletions src/PropertyDescriber/PropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ private function getHash(array $types): string
private function getPropertyDescriber(array $types, array $context): ?PropertyDescriberInterface
{
foreach ($this->propertyDescribers as $propertyDescriber) {
/* BC layer for Symfony < 6.3 @see https://symfony.com/doc/6.3/service_container/tags.html#reference-tagged-services */
if ($propertyDescriber instanceof self) {
continue;
}

// Prevent infinite recursion
if (\array_key_exists($this->getHash($types), $this->called)) {
if (\in_array($propertyDescriber, $this->called[$this->getHash($types)], true)) {
Expand Down
120 changes: 59 additions & 61 deletions tests/Functional/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ public function testControllers(?array $controller, ?string $fixtureName = null,

public static function provideAttributeTestCases(): \Generator
{
$type = Kernel::MAJOR_VERSION === 5 ? 'annotation' : 'attribute';

yield 'Promoted properties defaults attributes' => [
[
'name' => 'PromotedPropertiesController81',
'type' => $type,
'type' => 'attribute',
],
'PromotedPropertiesDefaults',
[],
Expand All @@ -94,78 +92,78 @@ public static function provideAttributeTestCases(): \Generator
yield 'JMS model opt out' => [
[
'name' => 'JmsOptOutController',
'type' => $type,
'type' => 'attribute',
],
'JmsOptOutController',
[new JMSSerializerBundle()],
[__DIR__.'/Configs/JMS.yaml'],
];

if (version_compare(Kernel::VERSION, '6.3.0', '>=')) {
yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2209' => [
[
'name' => 'Controller2209',
'type' => $type,
],
];
yield 'MapQueryString' => [
[
'name' => 'MapQueryStringController',
'type' => $type,
null,
[],
[__DIR__.'/Configs/EnableSerializer.yaml'],
],
];
yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [
[
'name' => 'MapQueryStringController',
'type' => $type,
],
'MapQueryStringCleanupComponents',
[],
[__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml', __DIR__.'/Configs/EnableSerializer.yaml'],
];

yield 'operationId must always be generated' => [
[
'name' => 'OperationIdController',
'type' => $type,
],
];

yield 'Symfony 6.3 MapQueryParameter attribute' => [
[
'name' => 'MapQueryParameterController',
'type' => $type,
],
];
yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2209' => [
[
'name' => 'Controller2209',
'type' => 'attribute',
],
];

yield 'Symfony 6.3 MapRequestPayload attribute' => [
[
'name' => 'MapRequestPayloadController',
'type' => $type,
],
yield 'MapQueryString' => [
[
'name' => 'MapQueryStringController',
'type' => 'attribute',
null,
[],
[__DIR__.'/Configs/EnableSerializer.yaml'],
];
],
];

yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2191' => [
[
'name' => 'MapQueryStringController',
'type' => 'attribute',
],
'MapQueryStringCleanupComponents',
[],
[__DIR__.'/Configs/CleanUnusedComponentsProcessor.yaml', __DIR__.'/Configs/EnableSerializer.yaml'],
];

yield 'operationId must always be generated' => [
[
'name' => 'OperationIdController',
'type' => 'attribute',
],
];

yield 'Symfony 6.3 MapQueryParameter attribute' => [
[
'name' => 'MapQueryParameterController',
'type' => 'attribute',
],
];

yield 'Symfony 6.3 MapRequestPayload attribute' => [
[
'name' => 'MapRequestPayloadController',
'type' => 'attribute',
],
null,
[],
[__DIR__.'/Configs/EnableSerializer.yaml'],
];

yield 'Create top level Tag from Tag attribute' => [
yield 'Create top level Tag from Tag attribute' => [
[
'name' => 'OpenApiTagController',
'type' => 'attribute',
],
];

if (property_exists(MapRequestPayload::class, 'type')) {
yield 'Symfony 7.1 MapRequestPayload array type' => [
[
'name' => 'OpenApiTagController',
'type' => $type,
'name' => 'MapRequestPayloadArray',
'type' => 'attribute',
],
];

if (property_exists(MapRequestPayload::class, 'type')) {
yield 'Symfony 7.1 MapRequestPayload array type' => [
[
'name' => 'MapRequestPayloadArray',
'type' => $type,
],
];
}
}
}

Expand Down
35 changes: 13 additions & 22 deletions tests/Functional/Entity/RangeInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;

use Symfony\Component\HttpKernel\Kernel;

trait RangeIntegerTrait
{
/**
Expand All @@ -38,24 +36,17 @@ trait RangeIntegerTrait
public $nullableRangeInt;
}

if (version_compare(Kernel::VERSION, '6.1', '>=')) {
class RangeInteger
{
use RangeIntegerTrait;

/**
* @var positive-int
*/
public $positiveInt;

/**
* @var negative-int
*/
public $negativeInt;
}
} else {
class RangeInteger
{
use RangeIntegerTrait;
}
class RangeInteger
{
use RangeIntegerTrait;

/**
* @var positive-int
*/
public $positiveInt;

/**
* @var negative-int
*/
public $negativeInt;
}
6 changes: 2 additions & 4 deletions tests/Functional/FOSRestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ public function testFOSRestAction(string $route): void

public static function provideRoute(): \Generator
{
yield 'Annotations' => ['/api/fosrest'];
yield ['/api/fosrest'];

if (TestKernel::isAttributesAvailable()) {
yield 'Attributes' => ['/api/fosrest_attributes'];
}
yield ['/api/fosrest_attributes'];
}
}
25 changes: 11 additions & 14 deletions tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use OpenApi\Attributes as OAAttributes;
use OpenApi\Generator;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Component\HttpKernel\Kernel;

class FunctionalTest extends WebTestCase
{
Expand Down Expand Up @@ -1234,19 +1233,17 @@ public function testRangeIntegers(): void
'type' => 'object',
];

if (version_compare(Kernel::VERSION, '6.1', '>=')) {
array_unshift($expected['required'], 'positiveInt', 'negativeInt');
$expected['properties'] += [
'positiveInt' => [
'type' => 'integer',
'minimum' => 1,
],
'negativeInt' => [
'type' => 'integer',
'maximum' => -1,
],
];
}
array_unshift($expected['required'], 'positiveInt', 'negativeInt');
$expected['properties'] += [
'positiveInt' => [
'type' => 'integer',
'minimum' => 1,
],
'negativeInt' => [
'type' => 'integer',
'maximum' => -1,
],
];

self::assertEquals($expected, json_decode($this->getModel('RangeInteger')->toJson(), true));
}
Expand Down
5 changes: 0 additions & 5 deletions tests/Functional/JMSFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,6 @@ public function testEnumSupport(): void
],
], json_decode($this->getModel('ArticleType81')->toJson(), true));

if (TestKernel::isAnnotationsAvailable()) {
// Further tests have only been defined with attributes
return;
}

self::assertEquals([
'schema' => 'ArticleType812',
'type' => 'string',
Expand Down
17 changes: 6 additions & 11 deletions tests/Functional/ModelDescriber/ObjectModelDescriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Nelmio\ApiDocBundle\Tests\Functional\WebTestCase;
use OpenApi\Annotations as OA;
use OpenApi\Annotations\OpenApi;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\PropertyInfo\Type as LegacyType;

class ObjectModelDescriberTest extends WebTestCase
Expand Down Expand Up @@ -92,11 +91,9 @@ public static function provideFixtures(): \Generator
Fixtures\ClassWithObject::class,
];

if (\PHP_VERSION_ID >= 80100) {
yield [
Fixtures\ClassWithIntersection::class,
];
}
yield [
Fixtures\ClassWithIntersection::class,
];

yield [
Fixtures\DateTimeClass::class,
Expand All @@ -106,11 +103,9 @@ public static function provideFixtures(): \Generator
Fixtures\UuidClass::class,
];

if (version_compare(Kernel::VERSION, '6.4.0', '>=')) {
yield [
Fixtures\UuidClass7And8::class,
];
}
yield [
Fixtures\UuidClass7And8::class,
];

yield [
Fixtures\Refs::class,
Expand Down
46 changes: 0 additions & 46 deletions tests/Functional/Resources/routes-attributes.yaml

This file was deleted.

Loading

0 comments on commit 367d892

Please sign in to comment.