Skip to content

Commit

Permalink
better annotation detection
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Mar 4, 2024
1 parent 1ff7236 commit 048356f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
3 changes: 2 additions & 1 deletion tests/Functional/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Nelmio\ApiDocBundle\Tests\Functional;

use Nelmio\ApiDocBundle\Tests\Helper;
use OpenApi\Annotations as OA;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelInterface;
Expand Down Expand Up @@ -56,7 +57,7 @@ public function testControllers(string $controllerName, ?string $fixtureName = n
$fixtureName = $fixtureName ?? $controllerName;

$routingConfiguration = function (RoutingConfigurator $routes) use ($controllerName) {
$routes->withPath('/')->import(__DIR__."/Controller/$controllerName.php", 'attribute');
$routes->withPath('/')->import(__DIR__."/Controller/$controllerName.php", Helper::isAnnotationsAvailable() ? 'annotation' : 'attribute');
};

$this->configurableContainerFactory->create([], $routingConfiguration, $extraConfigs);
Expand Down
11 changes: 2 additions & 9 deletions tests/Functional/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Nelmio\ApiDocBundle\Tests\Functional\Entity\SymfonyConstraintsWithValidationGroups;
use Nelmio\ApiDocBundle\Tests\Functional\ModelDescriber\NameConverter;
use Nelmio\ApiDocBundle\Tests\Functional\ModelDescriber\VirtualTypeClassDoesNotExistsHandlerDefinedDescriber;
use Nelmio\ApiDocBundle\Tests\Helper;
use ReflectionException;
use ReflectionMethod;
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
Expand Down Expand Up @@ -376,15 +377,7 @@ public function unserialize($str)

public static function isAnnotationsAvailable(): bool
{
if (Kernel::MAJOR_VERSION <= 5) {
return true;
}

if (Kernel::MAJOR_VERSION >= 7) {
return false;
}

return PHP_VERSION_ID < 80100;
return Helper::isAnnotationsAvailable();
}

public static function isAttributesAvailable(): bool
Expand Down
5 changes: 5 additions & 0 deletions tests/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public static function isCompoundValidatorConstraintSupported(): bool

return version_compare($validatorVersion, 'v5.1', '>=');
}

public static function isAnnotationsAvailable(): bool
{
return class_exists('Doctrine\Common\Annotations\Annotation');
}
}

0 comments on commit 048356f

Please sign in to comment.