public function testBindResultFromFormErrorSequence() { $bindResult = BindResult::fromFormErrorSequence(new FormErrorSequence(new FormError('foo', 'bar'))); $this->assertFalse($bindResult->isSuccess()); FormErrorAssertion::assertErrorMessages($this, $bindResult->getFormErrorSequence(), ['foo' => 'bar']); $this->expectException(AssertionFailedException::class); $bindResult->getValue(); }
public function bind(Data $data) : BindResult { $values = []; $formErrorSequence = new FormErrorSequence(); foreach ($data->getIndexes($this->key) as $index) { $bindResult = $this->wrappedMapping->withPrefixAndRelativeKey($this->key, $index)->bind($data); if (!$bindResult->isSuccess()) { $formErrorSequence = $formErrorSequence->merge($bindResult->getFormErrorSequence()); continue; } $values[] = $bindResult->getValue(); } if (!$formErrorSequence->isEmpty()) { return BindResult::fromFormErrorSequence($formErrorSequence); } return $this->applyConstraints($values, $this->key); }
public function bind(Data $data) : BindResult { $arguments = []; $formErrorSequence = new FormErrorSequence(); foreach ($this->mappings as $key => $mapping) { $bindResult = $mapping->bind($data); if (!$bindResult->isSuccess()) { $formErrorSequence = $formErrorSequence->merge($bindResult->getFormErrorSequence()); continue; } $arguments[$key] = $bindResult->getValue(); } if (!$formErrorSequence->isEmpty()) { return BindResult::fromFormErrorSequence($formErrorSequence); } $apply = $this->apply; $value = $apply(...array_values($arguments)); Assertion::isInstanceOf($value, $this->className); return $this->applyConstraints($value, $this->key); }