mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-03 08:09:25 +03:00
49 lines
1.6 KiB
PHP
49 lines
1.6 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 EXSyst\Component\Swagger\Schema;
|
|
use Nelmio\ApiDocBundle\ModelDescriber\Annotations\SymfonyConstraintAnnotationReader;
|
|
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;
|
|
};
|
|
$reflectionProperties = (new \ReflectionClass($entity))->getProperties();
|
|
$property = new Schema();
|
|
$schema = new Schema();
|
|
|
|
$symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(new AnnotationReader());
|
|
$symfonyConstraintAnnotationReader->setSchema($schema);
|
|
foreach ($reflectionProperties as $reflectionProperty) {
|
|
$symfonyConstraintAnnotationReader->updateProperty($reflectionProperty, $property);
|
|
}
|
|
|
|
// expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...])
|
|
$this->assertEquals($schema->getRequired(), ['property1', 'property2']);
|
|
}
|
|
}
|