Skip to content

Commit

Permalink
Test JMS enum support
Browse files Browse the repository at this point in the history
  • Loading branch information
javer committed Sep 16, 2023
1 parent d890c53 commit 448ccb1
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Tests/Functional/Controller/JMSController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;

use Symfony\Component\Routing\Annotation\Route;

if (\PHP_VERSION_ID >= 80100) {
/**
* @Route(host="api.example.com")
*/
class JMSController extends JMSController81
{
}
} else {
/**
* @Route(host="api.example.com")
*/
class JMSController extends JMSController80
{
}
}
26 changes: 26 additions & 0 deletions Tests/Functional/Controller/JMSController81.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;

use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\Article81;
use OpenApi\Attributes as OA;
use Symfony\Component\Routing\Annotation\Route;

class JMSController81 extends JMSController80
{
#[Route('/api/jms_enum', methods: ['GET'])]
#[OA\Response(response: '201', description: '', attachables: [new Model(type: Article81::class)])]
public function enum()
{
}
}
28 changes: 28 additions & 0 deletions Tests/Functional/JMSFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,34 @@ public function testNamingStrategyWithConstraints()
], json_decode($this->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);
Expand Down
6 changes: 6 additions & 0 deletions Tests/Functional/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 448ccb1

Please sign in to comment.