mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-03 16:19:26 +03:00
78664ef9ec
* Initial pass for OA3 upgrade * Fix Util Tests * Fix first batch of Unit Tests. Up to Model * Another batch of fixed tests * Update annotations * Convert Model & Property Describers * Update tests, Fix RouteDescribers, FIx additional bugs * Another batch of updates * Another batch of fixed Functional Tests * Fix FunctionalTest tests * Fix Bazinga Tests * FIx FOS Rest * Fix JMS TEsts & describers * Fix all Tests * Fix few stuff from own CR * CS Fixes * CS Fixes 2 * CS Fixes 3 * CS Fixes 4 * Remove collection bug * Updates after first CRs * CS * Drop support for SF3 * Update the docs * Add an upgrade guide * misc doc fixes * Configurable media types * Code Style Fixes * Don't use ::$ref for @Response and @RequestBody * Fix upgrading guide * Fix OA case Co-authored-by: Filip Benčo <filip.benco@websupport.sk> Co-authored-by: Guilhem Niot <guilhem.niot@gmail.com> Co-authored-by: Mantis Development <mantis@users.noreply.github.com>
77 lines
2.7 KiB
PHP
77 lines
2.7 KiB
PHP
<?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\ModelDescriber\Annotations;
|
|
|
|
use Doctrine\Common\Annotations\AnnotationReader;
|
|
use Nelmio\ApiDocBundle\ModelDescriber\Annotations\SymfonyConstraintAnnotationReader;
|
|
use OpenApi\Annotations as OA;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
class SymfonyConstraintAnnotationReaderTest extends TestCase
|
|
{
|
|
public function testUpdatePropertyFix1283()
|
|
{
|
|
$entity = new class() {
|
|
/**
|
|
* @Assert\NotBlank()
|
|
* @Assert\Length(min = 1)
|
|
*/
|
|
private $property1;
|
|
/**
|
|
* @Assert\NotBlank()
|
|
*/
|
|
private $property2;
|
|
};
|
|
|
|
$schema = new OA\Schema([]);
|
|
$schema->merge([new OA\Property(['property' => 'property1'])]);
|
|
$schema->merge([new OA\Property(['property' => 'property2'])]);
|
|
|
|
$symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(new AnnotationReader());
|
|
$symfonyConstraintAnnotationReader->setSchema($schema);
|
|
|
|
$symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]);
|
|
$symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property2'), $schema->properties[1]);
|
|
|
|
// expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...])
|
|
$this->assertEquals($schema->required, ['property1', 'property2']);
|
|
}
|
|
|
|
public function testAssertChoiceResultsInNumericArray()
|
|
{
|
|
define('TEST_ASSERT_CHOICE_STATUSES', [
|
|
1 => 'active',
|
|
2 => 'blocked',
|
|
]);
|
|
|
|
$entity = new class() {
|
|
/**
|
|
* @Assert\Length(min = 1)
|
|
* @Assert\Choice(choices=TEST_ASSERT_CHOICE_STATUSES)
|
|
*/
|
|
private $property1;
|
|
};
|
|
|
|
$schema = new OA\Schema([]);
|
|
$schema->merge([new OA\Property(['property' => 'property1'])]);
|
|
|
|
$symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(new AnnotationReader());
|
|
$symfonyConstraintAnnotationReader->setSchema($schema);
|
|
|
|
$symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]);
|
|
|
|
// expect enum to be numeric array with sequential keys (not [1 => "active", 2 => "active"])
|
|
$this->assertEquals($schema->properties[0]->enum, ['active', 'blocked']);
|
|
}
|
|
}
|