[Form] deprecated Form::hasErrors that isn't part of the Interface

This commit is contained in:
Tobias Schultze 2012-08-26 20:46:23 +02:00
parent a1e6cfbe15
commit 5cb82648ad
3 changed files with 51 additions and 48 deletions

View File

@ -754,7 +754,7 @@ class Form implements \IteratorAggregate, FormInterface
throw new \LogicException('You cannot call isValid() on a form that is not bound.'); throw new \LogicException('You cannot call isValid() on a form that is not bound.');
} }
if ($this->hasErrors()) { if (count($this->errors) > 0) {
return false; return false;
} }
@ -773,6 +773,9 @@ class Form implements \IteratorAggregate, FormInterface
* Returns whether or not there are errors. * Returns whether or not there are errors.
* *
* @return Boolean true if form is bound and not valid * @return Boolean true if form is bound and not valid
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Count
* {@link getErrors()} instead.
*/ */
public function hasErrors() public function hasErrors()
{ {

View File

@ -124,9 +124,9 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
$this->mapper->mapViolation($violation, $parent); $this->mapper->mapViolation($violation, $parent);
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $child->getErrors(), $child->getName() . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $child->getErrors(), $child->getName() . ' should have an error, but has none');
$this->assertFalse($grandChild->hasErrors(), $grandChild->getName() . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName() . ' should not have an error, but has one');
} }
public function testFollowDotRules() public function testFollowDotRules()
@ -149,9 +149,9 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
$this->mapper->mapViolation($violation, $parent); $this->mapper->mapViolation($violation, $parent);
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertFalse($child->hasErrors(), $child->getName() . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $child->getName() . ' should not have an error, but has one');
$this->assertFalse($grandChild->hasErrors(), $grandChild->getName() . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName() . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $grandGrandChild->getErrors(), $grandGrandChild->getName() . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $grandGrandChild->getErrors(), $grandGrandChild->getName() . ' should have an error, but has none');
} }
@ -172,9 +172,9 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
$this->mapper->mapViolation($violation, $parent); $this->mapper->mapViolation($violation, $parent);
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertFalse($child->hasErrors(), $child->getName() . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $child->getName() . ' should not have an error, but has one');
$this->assertFalse($grandChild->hasErrors(), $grandChild->getName() . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName() . ' should not have an error, but has one');
} }
public function testAbortVirtualFormMappingIfNotSynchronized() public function testAbortVirtualFormMappingIfNotSynchronized()
@ -194,9 +194,9 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
$this->mapper->mapViolation($violation, $parent); $this->mapper->mapViolation($violation, $parent);
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertFalse($child->hasErrors(), $child->getName() . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $child->getName() . ' should not have an error, but has one');
$this->assertFalse($grandChild->hasErrors(), $grandChild->getName() . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName() . ' should not have an error, but has one');
} }
public function testAbortDotRuleMappingIfNotSynchronized() public function testAbortDotRuleMappingIfNotSynchronized()
@ -218,9 +218,9 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
$this->mapper->mapViolation($violation, $parent); $this->mapper->mapViolation($violation, $parent);
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertFalse($child->hasErrors(), $child->getName() . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $child->getName() . ' should not have an error, but has one');
$this->assertFalse($grandChild->hasErrors(), $grandChild->getName() . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName() . ' should not have an error, but has one');
} }
public function provideDefaultTests() public function provideDefaultTests()
@ -732,15 +732,15 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
if (self::LEVEL_0 === $target) { if (self::LEVEL_0 === $target) {
$this->assertEquals(array($this->getFormError()), $parent->getErrors(), $parent->getName() . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $parent->getErrors(), $parent->getName() . ' should have an error, but has none');
$this->assertFalse($child->hasErrors(), $childName . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $childName . ' should not have an error, but has one');
$this->assertFalse($grandChild->hasErrors(), $grandChildName . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChildName . ' should not have an error, but has one');
} elseif (self::LEVEL_1 === $target) { } elseif (self::LEVEL_1 === $target) {
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $child->getErrors(), $childName . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $child->getErrors(), $childName . ' should have an error, but has none');
$this->assertFalse($grandChild->hasErrors(), $grandChildName . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChildName . ' should not have an error, but has one');
} else { } else {
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertFalse($child->hasErrors(), $childName . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $childName . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChildName. ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChildName. ' should have an error, but has none');
} }
} }
@ -1199,20 +1199,20 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
$this->mapper->mapViolation($violation, $parent); $this->mapper->mapViolation($violation, $parent);
if ($target !== self::LEVEL_0) { if ($target !== self::LEVEL_0) {
$this->assertFalse($distraction->hasErrors(), 'distraction should not have an error, but has one'); $this->assertCount(0, $distraction->getErrors(), 'distraction should not have an error, but has one');
} }
if (self::LEVEL_0 === $target) { if (self::LEVEL_0 === $target) {
$this->assertEquals(array($this->getFormError()), $parent->getErrors(), $parent->getName() . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $parent->getErrors(), $parent->getName() . ' should have an error, but has none');
$this->assertFalse($child->hasErrors(), $childName . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $childName . ' should not have an error, but has one');
$this->assertFalse($grandChild->hasErrors(), $grandChildName . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChildName . ' should not have an error, but has one');
} elseif (self::LEVEL_1 === $target) { } elseif (self::LEVEL_1 === $target) {
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $child->getErrors(), $childName . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $child->getErrors(), $childName . ' should have an error, but has none');
$this->assertFalse($grandChild->hasErrors(), $grandChildName . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChildName . ' should not have an error, but has one');
} else { } else {
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertFalse($child->hasErrors(), $childName . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $childName . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChildName. ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChildName. ' should have an error, but has none');
} }
} }
@ -1385,24 +1385,24 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
$this->mapper->mapViolation($violation, $parent); $this->mapper->mapViolation($violation, $parent);
if (self::LEVEL_0 === $target) { if (self::LEVEL_0 === $target) {
$this->assertFalse($errorChild->hasErrors(), $errorName . ' should not have an error, but has one'); $this->assertCount(0, $errorChild->getErrors(), $errorName . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $parent->getErrors(), $parent->getName() . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $parent->getErrors(), $parent->getName() . ' should have an error, but has none');
$this->assertFalse($child->hasErrors(), $childName . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $childName . ' should not have an error, but has one');
$this->assertFalse($grandChild->hasErrors(), $grandChildName . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChildName . ' should not have an error, but has one');
} elseif (self::LEVEL_1 === $target) { } elseif (self::LEVEL_1 === $target) {
$this->assertFalse($errorChild->hasErrors(), $errorName . ' should not have an error, but has one'); $this->assertCount(0, $errorChild->getErrors(), $errorName . ' should not have an error, but has one');
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $child->getErrors(), $childName . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $child->getErrors(), $childName . ' should have an error, but has none');
$this->assertFalse($grandChild->hasErrors(), $grandChildName . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChildName . ' should not have an error, but has one');
} elseif (self::LEVEL_1B === $target) { } elseif (self::LEVEL_1B === $target) {
$this->assertEquals(array($this->getFormError()), $errorChild->getErrors(), $errorName . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $errorChild->getErrors(), $errorName . ' should have an error, but has none');
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertFalse($child->hasErrors(), $childName . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $childName . ' should not have an error, but has one');
$this->assertFalse($grandChild->hasErrors(), $grandChildName . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChildName . ' should not have an error, but has one');
} else { } else {
$this->assertFalse($errorChild->hasErrors(), $errorName . ' should not have an error, but has one'); $this->assertCount(0, $errorChild->getErrors(), $errorName . ' should not have an error, but has one');
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertFalse($child->hasErrors(), $childName . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $childName . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChildName. ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChildName. ' should have an error, but has none');
} }
} }
@ -1449,15 +1449,15 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
if (self::LEVEL_0 === $target) { if (self::LEVEL_0 === $target) {
$this->assertEquals(array($this->getFormError()), $parent->getErrors(), $parent->getName() . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $parent->getErrors(), $parent->getName() . ' should have an error, but has none');
$this->assertFalse($child->hasErrors(), $childName . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $childName . ' should not have an error, but has one');
$this->assertFalse($grandChild->hasErrors(), $grandChildName . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChildName . ' should not have an error, but has one');
} elseif (self::LEVEL_1 === $target) { } elseif (self::LEVEL_1 === $target) {
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $child->getErrors(), $childName . ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $child->getErrors(), $childName . ' should have an error, but has none');
$this->assertFalse($grandChild->hasErrors(), $grandChildName . ' should not have an error, but has one'); $this->assertCount(0, $grandChild->getErrors(), $grandChildName . ' should not have an error, but has one');
} else { } else {
$this->assertFalse($parent->hasErrors(), $parent->getName() . ' should not have an error, but has one'); $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
$this->assertFalse($child->hasErrors(), $childName . ' should not have an error, but has one'); $this->assertCount(0, $child->getErrors(), $childName . ' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChildName. ' should have an error, but has none'); $this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChildName. ' should have an error, but has none');
} }
} }

View File

@ -231,12 +231,12 @@ class SimpleFormTest extends AbstractFormTest
{ {
$this->form->addError(new FormError('Error!')); $this->form->addError(new FormError('Error!'));
$this->assertTrue($this->form->hasErrors()); $this->assertCount(1, $this->form->getErrors());
} }
public function testHasNoErrors() public function testHasNoErrors()
{ {
$this->assertFalse($this->form->hasErrors()); $this->assertCount(0, $this->form->getErrors());
} }
/** /**