Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit edc7f87

Browse filesBrowse files
tobias-93Tobias Feijten
authored and
Tobias Feijten
committed
[Validator] Extend ValidTest with attribute test
1 parent 4e5e1e0 commit edc7f87
Copy full SHA for edc7f87

File tree

Expand file treeCollapse file tree

1 file changed

+32
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+32
-0
lines changed

‎src/Symfony/Component/Validator/Tests/Constraints/ValidTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/ValidTest.php
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Validator\Constraints\Valid;
16+
use Symfony\Component\Validator\Mapping\ClassMetadata;
17+
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
1618

1719
/**
1820
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -32,4 +34,34 @@ public function testGroupsAreNullByDefault()
3234

3335
$this->assertNull($constraint->groups);
3436
}
37+
38+
/**
39+
* @requires PHP 8
40+
*/
41+
public function testAttributes()
42+
{
43+
$metadata = new ClassMetaData(ValidDummy::class);
44+
$loader = new AnnotationLoader();
45+
self::assertTrue($loader->loadClassMetadata($metadata));
46+
47+
[$bConstraint] = $metadata->properties['b']->getConstraints();
48+
self::assertFalse($bConstraint->traverse);
49+
self::assertSame(['traverse_group'], $bConstraint->groups);
50+
51+
[$cConstraint] = $metadata->properties['c']->getConstraints();
52+
self::assertSame(['my_group'], $cConstraint->groups);
53+
self::assertSame('some attached data', $cConstraint->payload);
54+
}
55+
}
56+
57+
class ValidDummy
58+
{
59+
#[Valid]
60+
private $a;
61+
62+
#[Valid(groups: ['traverse_group'], traverse: false)] // Needs a group to work at all for this test
63+
private $b;
64+
65+
#[Valid(groups: ['my_group'], payload: 'some attached data')]
66+
private $c;
3567
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.