Skip to content

Commit

Permalink
Add tests for annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvandevijver committed Oct 11, 2024
1 parent 540b3cf commit 0c26788
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 4 deletions.
15 changes: 15 additions & 0 deletions tests/Functional/Controller/JMSController80.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Nelmio\ApiDocBundle\Tests\Functional\Entity\DiscriminatorMap\JMSAbstractUser;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex80;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSDualComplex;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSEnum;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSNamingStrategyConstraints;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChat;
Expand Down Expand Up @@ -166,4 +167,18 @@ public function minUserNestedAction()
public function discriminatorMapAction()
{
}

/**
* @Route("/api/jms_enum_array", methods={"GET"})
*
* @OA\Response(
* response=200,
* description="Success",
*
* @Model(type=JMSEnum::class)
* )
*/
public function enumArrayAction()
{
}
}
4 changes: 2 additions & 2 deletions tests/Functional/Controller/JMSController81.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Nelmio\ApiDocBundle\Tests\Functional\Entity\DiscriminatorMap\JMSAbstractUser;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex81;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSDualComplex;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSEnum81;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSEnum;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSNamingStrategyConstraints;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChat;
Expand Down Expand Up @@ -147,7 +147,7 @@ public function discriminatorMapAction()
#[OA\Response(
response: 200,
description: 'Success',
content: new Model(type: JMSEnum81::class))
content: new Model(type: JMSEnum::class))
]
public function enumArrayAction()
{
Expand Down
24 changes: 24 additions & 0 deletions tests/Functional/Entity/JMSEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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\Entity;

use Nelmio\ApiDocBundle\Tests\Functional\TestKernel;

if (TestKernel::isAnnotationsAvailable()) {
class JMSEnum extends JMSEnum80
{
}
} else {
class JMSEnum extends JMSEnum81
{
}
}
45 changes: 45 additions & 0 deletions tests/Functional/Entity/JMSEnum80.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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\Entity;

use JMS\Serializer\Annotation as Serializer;

class JMSEnum80
{
/**
* @Serializer\Type("enum<Nelmio\ApiDocBundle\Tests\Functional\Entity\ArticleType81, 'value'>")
*
* @Serializer\Expose()
*/
public $enumValue;

/**
* @Serializer\Type("array<enum<Nelmio\ApiDocBundle\Tests\Functional\Entity\ArticleType81, 'value'>>")
*
* @Serializer\Expose()
*/
public $enumValues;

/**
* @Serializer\Type("enum<Nelmio\ApiDocBundle\Tests\Functional\Entity\ArticleType81, 'name'>")
*
* @Serializer\Expose()
*/
public $enumName;

/**
* @Serializer\Type("array<enum<Nelmio\ApiDocBundle\Tests\Functional\Entity\ArticleType81, 'name'>>")
*
* @Serializer\Expose()
*/
public $enumNames;
}
4 changes: 2 additions & 2 deletions tests/Functional/JMSFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public function testEnumSupport(): void
], json_decode($this->getModel('ArticleType81')->toJson(), true));

self::assertEquals([
'schema' => 'JMSEnum81',
'schema' => 'JMSEnum',
'type' => 'object',
'properties' => [
'enum_value' => [
Expand All @@ -394,7 +394,7 @@ public function testEnumSupport(): void
]
],
]
], json_decode($this->getModel('JMSEnum81')->toJson(), true));
], json_decode($this->getModel('JMSEnum')->toJson(), true));

self::assertEquals([
'schema' => 'ArticleType81',
Expand Down

0 comments on commit 0c26788

Please sign in to comment.