2021-11-06 07:13:56 -05:00
|
|
|
<?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;
|
|
|
|
|
2021-12-19 11:41:36 +01:00
|
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
|
|
|
|
2021-11-06 07:13:56 -05:00
|
|
|
class ValidationGroupsFunctionalTest extends WebTestCase
|
|
|
|
{
|
2021-12-19 11:41:36 +01:00
|
|
|
protected static function createKernel(array $options = []): KernelInterface
|
2021-11-06 07:13:56 -05:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|