public function testIsValid() { $result = new \r8\Validator\Result("Wakka"); $this->assertTrue($result->isValid()); $result->addError("Test Error"); $this->assertFalse($result->isValid()); $result->clearErrors(); $this->assertTrue($result->isValid()); }
public function testDuplicateErrors() { $result1 = new \r8\Validator\Result("example value"); $result1->addError("This is an Error"); $valid1 = $this->getMock("r8\\iface\\Validator"); $valid1->expects($this->once())->method("validate")->with($this->equalTo("example value"))->will($this->returnValue($result1)); $result2 = new \r8\Validator\Result("example value"); $result2->addError("This is an Error"); $valid2 = $this->getMock("r8\\iface\\Validator"); $valid2->expects($this->once())->method("validate")->with($this->equalTo("example value"))->will($this->returnValue($result2)); $any = new \r8\Validator\Any($valid1, $valid2); $result = $any->validate("example value"); $this->assertThat($result, $this->isInstanceOf("r8\\Validator\\Result")); $this->assertFalse($result->isValid()); $this->assertEquals(array("This is an Error"), $result->getErrors()); }
public function testResultObjectResult() { $valid = new \r8\Validator\Callback(function ($value) { $result = new \r8\Validator\Result($value); if ($value > 10) { $result->addError("Error one")->addError("error two"); } return $result; }); $this->assertTrue($valid->isValid(5)); $result = $valid->validate(20); $this->assertFalse($result->isValid()); $this->assertEquals(array("Error one", "error two"), $result->getErrors()); }