mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-03 08:09:25 +03:00
7357de9c16
If this was turned on by default, that seems like a _large_ BC break as folks entire OpenAPI doc could change underneath them. The config option defaults to false and users can enable it if they desire.
78 lines
2.2 KiB
PHP
78 lines
2.2 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\Functional;
|
|
|
|
class ValidationGroupsFunctionalTest extends WebTestCase
|
|
{
|
|
protected static function createKernel(array $options = [])
|
|
{
|
|
return new TestKernel(TestKernel::USE_VALIDATION_GROUPS);
|
|
}
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
static::createClient([], ['HTTP_HOST' => 'api.example.com']);
|
|
}
|
|
|
|
public function testConstraintGroupsAreRespectedWhenDescribingModels()
|
|
{
|
|
$expected = [
|
|
'required' => [
|
|
'property',
|
|
],
|
|
'properties' => [
|
|
'property' => [
|
|
'type' => 'integer',
|
|
// the min/max constraint is in the default group only and shouldn't
|
|
// be read here with validation groups turned on
|
|
],
|
|
],
|
|
'type' => 'object',
|
|
'schema' => 'SymfonyConstraintsTestGroup',
|
|
];
|
|
|
|
$this->assertEquals(
|
|
$expected,
|
|
json_decode($this->getModel('SymfonyConstraintsTestGroup')->toJson(), true)
|
|
);
|
|
}
|
|
|
|
public function testConstraintDefaultGroupsAreRespectedWhenReadingAnnotations()
|
|
{
|
|
$expected = [
|
|
'properties' => [
|
|
'property' => [
|
|
'type' => 'integer',
|
|
// min/max will be read here as they are in th e default group
|
|
'maximum' => 100,
|
|
'minimum' => 1,
|
|
],
|
|
'propertyInDefaultGroup' => [
|
|
'type' => 'integer',
|
|
// min/max will be read here as they are in th e default group
|
|
'maximum' => 100,
|
|
'minimum' => 1,
|
|
],
|
|
],
|
|
'type' => 'object',
|
|
'schema' => 'SymfonyConstraintsDefaultGroup',
|
|
];
|
|
|
|
$this->assertEquals(
|
|
$expected,
|
|
json_decode($this->getModel('SymfonyConstraintsDefaultGroup')->toJson(), true)
|
|
);
|
|
}
|
|
}
|