Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a375dfb

Browse files
committed
[Validator] Add hasViolations method to ConstraintViolationList
1 parent e891d55 commit a375dfb

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* not setting the `strict` option of the `Choice` constraint to `true` is
88
deprecated and will throw an exception in Symfony 4.0
99
* setting the `checkDNS` option of the `Url` constraint to `true` is deprecated in favor of constant values and will throw an exception in Symfony 4.0
10+
* added `ConstraintViolationList::hasViolations()`
1011

1112
3.3.0
1213
-----

src/Symfony/Component/Validator/ConstraintViolationList.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,14 @@ public function findByCodes($codes)
178178

179179
return new static($violations);
180180
}
181+
182+
/**
183+
* Returns whether this object contains violations.
184+
*
185+
* @return bool
186+
*/
187+
public function hasViolations()
188+
{
189+
return (bool) $this->violations;
190+
}
181191
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ public function testFindByCodes($code, $violationsCount)
146146
$this->assertCount($violationsCount, $specificErrors);
147147
}
148148

149+
public function testHasViolations()
150+
{
151+
$list = new ConstraintViolationList();
152+
153+
$this->assertFalse($list->hasViolations());
154+
$list->add($this->getViolation('Error'));
155+
$this->assertTrue($list->hasViolations());
156+
$list->remove(0);
157+
$this->assertFalse($list->hasViolations());
158+
}
159+
149160
public function findByCodesProvider()
150161
{
151162
return array(

0 commit comments

Comments
 (0)