public function testMerge()
 {
     $formErrorSequenceA = new FormErrorSequence(new FormError('foo', ''));
     $formErrorSequenceB = new FormErrorSequence(new FormError('bar', ''));
     $formErrorSequenceC = $formErrorSequenceA->merge($formErrorSequenceB);
     $this->assertNotSame($formErrorSequenceA, $formErrorSequenceC);
     $this->assertNotSame($formErrorSequenceB, $formErrorSequenceC);
     $this->assertCount(2, $formErrorSequenceC);
 }
Exemple #2
0
 public function __invoke(FormErrorSequence $errors, array $htmlAttributes = []) : string
 {
     if ($errors->isEmpty()) {
         return '';
     }
     $errorFormatter = $this->errorFormatter;
     $document = new DOMDocument('1.0', 'utf-8');
     $list = $document->createElement('ul');
     $document->appendChild($list);
     $this->addAttributes($list, $htmlAttributes);
     foreach ($errors as $error) {
         /* @var $error FormError */
         $list->appendChild($document->createElement('li', htmlspecialchars($errorFormatter($error->getMessage(), $error->getArguments()))));
     }
     return $document->saveHTML($list);
 }
Exemple #3
0
 public function getField(string $key) : Field
 {
     return new Field($key, $this->data->getValue($key, ''), $this->errors->collect($key), $this->data);
 }
Exemple #4
0
 public function hasErrors() : bool
 {
     return !$this->errors->isEmpty();
 }