Skip to content

Commit 8031652

Browse files
committed
fix(symfony): missing GroupSequence type for validation groups
fixes #7228
1 parent e1191ca commit 8031652

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

src/Symfony/Validator/ValidationGroupsExtractorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ trait ValidationGroupsExtractorTrait
2323
*/
2424
private ?ContainerInterface $container = null;
2525

26-
public function getValidationGroups(\Closure|array|string|null $validationGroups, ?object $data = null): string|array|GroupSequence|null
26+
public function getValidationGroups(\Closure|array|GroupSequence|string|null $validationGroups, ?object $data = null): string|array|GroupSequence|null
2727
{
2828
if (null === $validationGroups) {
2929
return $validationGroups;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue7228;
15+
16+
use ApiPlatform\Metadata\Post;
17+
use Symfony\Component\Validator\Constraints\GroupSequence;
18+
19+
#[Post(uriTemplate: 'issue7228', validationContext: ['groups' => new GroupSequence(['P1', 'P2'])])]
20+
class ValidationGroupSequence
21+
{
22+
public function __construct(
23+
public string $id = '1',
24+
) {
25+
}
26+
}

tests/Functional/ValidationTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Functional;
15+
16+
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
17+
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue7228\ValidationGroupSequence;
18+
use ApiPlatform\Tests\SetupClassResourcesTrait;
19+
20+
class ValidationTest extends ApiTestCase
21+
{
22+
use SetupClassResourcesTrait;
23+
24+
protected static ?bool $alwaysBootKernel = false;
25+
26+
/**
27+
* @return class-string[]
28+
*/
29+
public static function getResources(): array
30+
{
31+
return [ValidationGroupSequence::class];
32+
}
33+
34+
public function testValidationGroupSequence(): void
35+
{
36+
$this->createClient()->request('POST', 'issue7228', ['headers' => ['content-type' => 'application/ld+json'], 'json' => ['id' => '1']]);
37+
$this->assertResponseIsSuccessful();
38+
}
39+
}

0 commit comments

Comments
 (0)