Skip to content

Commit

Permalink
Add support for validation from metadata (e.g., annotations)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeboer committed Dec 9, 2017
1 parent 9a4c0ed commit 7dac2e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
17 changes: 17 additions & 0 deletions spec/Step/ValidatorStepSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,21 @@ function($item) use ($step, $next) {
}
);
}

function it_validates_an_item_from_metadata(
ValidatorInterface $validator,
ConstraintViolationListInterface $list
) {
$next = function() {};
$list->count()->willReturn(1);
$item = new \stdClass();
$validator->validate($item)->willReturn($list);

$this->process(
$item,
$next
);

$this->getViolations()->shouldReturn([1 => $list]);
}
}
8 changes: 6 additions & 2 deletions src/Step/ValidatorStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ public function getViolations()
*/
public function process($item, callable $next)
{
$constraints = new Constraints\Collection($this->constraints);
$list = $this->validator->validate($item, $constraints);
if (count($this->constraints) > 0) {
$constraints = new Constraints\Collection($this->constraints);
$list = $this->validator->validate($item, $constraints);
} else {
$list = $this->validator->validate($item);
}

if (count($list) > 0) {
$this->violations[$this->line] = $list;
Expand Down

0 comments on commit 7dac2e6

Please sign in to comment.