8000 feature #41154 [Validator] Add support for `ConstraintViolationList::… · symfony/symfony@0ff660c · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ff660c

Browse files
committed
feature #41154 [Validator] Add support for ConstraintViolationList::createFromMessage() (lyrixx)
This PR was merged into the 5.4 branch. Discussion ---------- [Validator] Add support for `ConstraintViolationList::createFromMessage()` | Q | A | ------------- | --- | Branch? | 5.x (5.4) | Bug fix? | no | New feature? | ye | Deprecations? | no | Tickets | Fix #41111 | License | MIT | Doc PR | Commits ------- d4b6436 [Validator] Add support for `ConstraintViolationList::createFromMessage()`
2 parents 5778f9a + d4b6436 commit 0ff660c

File tree

3 files changed

+21
-0
lines changed
  • src/Symfony/Component/Validator

3 files changed

+21
-0
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHANGELOG
22
=========
33

4+
5.4
5+
---
6+
* Add support for `ConstraintViolationList::createFromMessage()`
7+
48
5.3
59
---
610
* Add the `normalizer` option to the `Unique` constraint

src/Symfony/Component/Validator/ConstraintViolationList.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public function __construct(array $violations = [])
3535
}
3636
}
3737

38+
public static function createFromMessage(string $message): self
39+
{
40+
$self = new self();
41+
$self->add(new ConstraintViolation($message, '', [], null, '', null));
42+
43+
return $self;
44+
}
45+
3846
/**
3947
* Converts the violation into a string for debugging purposes.
4048
*

src/Symfony/Component/Validator/Tests/ConstraintViolationListTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ public function findByCodesProvider()
155155
];
156156
}
157157

158+
public function testCreateFromMessage()
159+
{
160+
$list = ConstraintViolationList::createFromMessage('my message');
161+
162+
$this->assertCount(1, $list);
163+
$this->assertInstanceOf(ConstraintViolation::class, $list[0]);
164+
$this->assertSame('my message', $list[0]->getMessage());
165+
}
166+
158167
protected function getViolation($message, $root = null, $propertyPath = null, $code = null)
159168
{
160169
return new ConstraintViolation($message, $message, [], $root, $propertyPath, null, null, $code);

0 commit comments

Comments
 (0)
0