Exemple #1
0
 /**
  * @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());
 }
Exemple #2
0
 /**
  * @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;
 }
Exemple #3
0
 /**
  * @return boolean
  */
 public function isEmptyErrors()
 {
     return $this->errors ? $this->errors->isEmpty() : true;
 }
Exemple #4
0
 /**
  * @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;
 }
Exemple #5
0
 /**
  * @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);
 }