/** * @covers ::onlyFor */ public function testOnlyFor() { $errorObjects = [new Error(new Present('name1', 'test 1 :name')), new Error(new Present('name1', 'test 2 :name')), new Error(new Present('name2', 'test 3 :name'))]; $errors = new Errors($errorObjects); $filtered = $errors->onlyFor('name1'); $this->assertEquals('test 1 name1, test 2 name1', $filtered->humanize()); }
/** * @param string $name * @return Errors */ public function onlyFor($name) { $errors = new Errors(); foreach ($this->errors as $error) { if ($error->getName() === $name) { $errors->add($error); } } return $errors; }
/** * @return boolean */ public function isEmptyErrors() { return $this->errors ? $this->errors->isEmpty() : true; }
/** * @param object $subject * @return Errors */ public function getErrors($subject) { $errors = new Errors(); foreach ($this->asserts as $assert) { if ($error = $assert->getError($subject)) { $errors->add($error); } } return $errors; }
/** * @param object $subject * @param Errors $errors * @param integer $code * @param Exception $previous */ public function __construct($subject, Errors $errors, $code = 0, Exception $previous = null) { $this->subject = $subject; $this->errors = $errors; parent::__construct("Has errors: {$errors->humanize()}", $code, $previous); }