-
Notifications
You must be signed in to change notification settings - Fork 937
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get string when backed enum type is string
- Loading branch information
Showing
3 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OpenApi\Tests\Fixtures\PHP; | ||
|
||
use OpenApi\Attributes\Schema; | ||
|
||
#[Schema()] | ||
enum StatusEnumStringBacked: string | ||
{ | ||
case DRAFT = 'draft'; | ||
case PUBLISHED = 'published'; | ||
case ARCHIVED = 'archived'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,56 @@ | ||
<?php declare(strict_types=1); | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* @license Apache 2.0 | ||
*/ | ||
|
||
namespace OpenApi\Tests\Processors; | ||
|
||
use OpenApi\Analysers\AttributeAnnotationFactory; | ||
use OpenApi\Analysers\DocBlockAnnotationFactory; | ||
use OpenApi\Analysers\ReflectionAnalyser; | ||
use OpenApi\Analysers\TokenAnalyser; | ||
use OpenApi\Processors\ExpandEnums; | ||
use OpenApi\Tests\Fixtures\PHP\StatusEnum; | ||
use OpenApi\Tests\Fixtures\PHP\StatusEnumBacked; | ||
use OpenApi\Tests\Fixtures\PHP\StatusEnumStringBacked; | ||
use OpenApi\Tests\OpenApiTestCase; | ||
|
||
class ExpandEnumsTest extends OpenApiTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
if (! class_exists('\\ReflectionEnum')) { | ||
if ($this->getAnalyzer() instanceof TokenAnalyser) { | ||
$this->markTestSkipped(); | ||
} | ||
} | ||
|
||
public function testExpandUnitEnum(): void | ||
{ | ||
$analysis = $this->analysisFromFixtures(['PHP/StatusEnum.php']); | ||
$analysis = $this->analysisFromFixtures(['PHP/StatusEnum.php'], [], $this->getAnalyzer()); | ||
$analysis->process([new ExpandEnums()]); | ||
$schema = $analysis->getSchemaForSource(StatusEnum::class); | ||
|
||
self::assertEquals(['DRAFT', 'PUBLISHED', 'ARCHIVED'], $schema->enum); | ||
} | ||
} | ||
|
||
public function testExpandBackedEnum(): void | ||
{ | ||
$analysis = $this->analysisFromFixtures(['PHP/StatusEnumBacked.php'], [], $this->getAnalyzer()); | ||
$analysis->process([new ExpandEnums()]); | ||
$schema = $analysis->getSchemaForSource(StatusEnumBacked::class); | ||
|
||
self::assertEquals(['DRAFT', 'PUBLISHED', 'ARCHIVED'], $schema->enum); | ||
} | ||
|
||
public function testExpandBackedStringEnum(): void | ||
{ | ||
$analysis = $this->analysisFromFixtures(['PHP/StatusEnumStringBacked.php'], [], $this->getAnalyzer()); | ||
$analysis->process([new ExpandEnums()]); | ||
$schema = $analysis->getSchemaForSource(StatusEnumStringBacked::class); | ||
|
||
self::assertEquals(['draft', 'published', 'archived'], $schema->enum); | ||
} | ||
} |