forked from api-platform/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: resource with enum properties schema
- Loading branch information
1 parent
4c3253f
commit 0f384f5
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
tests/Fixtures/TestBundle/ApiResource/ResourceWithEnumProperty.php
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,58 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\GetCollection; | ||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Enum\GenderTypeEnum; | ||
|
||
#[ApiResource()] | ||
#[Get( | ||
provider: self::class.'::providerItem', | ||
)] | ||
#[GetCollection( | ||
provider: self::class.'::providerCollection', | ||
)] | ||
class ResourceWithEnumProperty | ||
{ | ||
public int $id = 1; | ||
|
||
public ?BackedEnumIntegerResource $intEnum = null; | ||
|
||
/** @var BackedEnumStringResource[] */ | ||
public array $stringEnum = []; | ||
|
||
public ?GenderTypeEnum $gender = null; | ||
|
||
/** @var GenderTypeEnum[] */ | ||
public array $genders = []; | ||
|
||
public static function providerItem(Operation $operation, array $uriVariables): self | ||
{ | ||
$self = new self(); | ||
$self->intEnum = BackedEnumIntegerResource::Yes; | ||
$self->stringEnum = [BackedEnumStringResource::Maybe, BackedEnumStringResource::No]; | ||
$self->gender = GenderTypeEnum::FEMALE; | ||
$self->genders = [GenderTypeEnum::FEMALE, GenderTypeEnum::MALE]; | ||
|
||
return $self; | ||
} | ||
|
||
public static function providerCollection(Operation $operation, array $uriVariables): array | ||
{ | ||
return [self::providerItem($operation, $uriVariables)]; | ||
} | ||
} |
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