From 448ccb1769c81b4e82760b8b0df0819a834f4b3b Mon Sep 17 00:00:00 2001 From: javer Date: Sat, 16 Sep 2023 17:51:15 +0300 Subject: [PATCH] Test JMS enum support --- Tests/Functional/Controller/JMSController.php | 30 +++++++++++++++++++ .../Functional/Controller/JMSController81.php | 26 ++++++++++++++++ Tests/Functional/JMSFunctionalTest.php | 28 +++++++++++++++++ Tests/Functional/TestKernel.php | 6 ++++ 4 files changed, 90 insertions(+) create mode 100644 Tests/Functional/Controller/JMSController.php create mode 100644 Tests/Functional/Controller/JMSController81.php diff --git a/Tests/Functional/Controller/JMSController.php b/Tests/Functional/Controller/JMSController.php new file mode 100644 index 000000000..11788606b --- /dev/null +++ b/Tests/Functional/Controller/JMSController.php @@ -0,0 +1,30 @@ += 80100) { + /** + * @Route(host="api.example.com") + */ + class JMSController extends JMSController81 + { + } +} else { + /** + * @Route(host="api.example.com") + */ + class JMSController extends JMSController80 + { + } +} diff --git a/Tests/Functional/Controller/JMSController81.php b/Tests/Functional/Controller/JMSController81.php new file mode 100644 index 000000000..b81ca9a5c --- /dev/null +++ b/Tests/Functional/Controller/JMSController81.php @@ -0,0 +1,26 @@ +getModel('JMSNamingStrategyConstraints')->toJson(), true)); } + /** + * @requires PHP >= 8.1 + */ + public function testEnumSupport() + { + $this->assertEquals([ + 'type' => 'object', + 'properties' => [ + 'id' => [ + 'type' => 'integer', + ], + 'type' => [ + '$ref' => '#/components/schemas/ArticleType81', + ], + ], + 'schema' => 'Article81', + ], json_decode($this->getModel('Article81')->toJson(), true)); + + $this->assertEquals([ + 'schema' => 'ArticleType81', + 'type' => 'string', + 'enum' => [ + 'draft', + 'final', + ], + ], json_decode($this->getModel('ArticleType81')->toJson(), true)); + } + protected static function createKernel(array $options = []): KernelInterface { return new TestKernel(TestKernel::USE_JMS); diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index d2aa13978..286852618 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -310,6 +310,12 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load ], ]); + if ($this->flags & self::USE_JMS && \PHP_VERSION_ID >= 80100) { + $c->loadFromExtension('jms_serializer', [ + 'enum_support' => true, + ]); + } + $def = new Definition(VirtualTypeClassDoesNotExistsHandlerDefinedDescriber::class); $def->addTag('nelmio_api_doc.model_describer'); $c->setDefinition('nelmio.test.jms.virtual_type.describer', $def);