diff --git a/spec/Step/ValidatorStepSpec.php b/spec/Step/ValidatorStepSpec.php index 69a3e55..86624dd 100644 --- a/spec/Step/ValidatorStepSpec.php +++ b/spec/Step/ValidatorStepSpec.php @@ -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]); + } } diff --git a/src/Step/ValidatorStep.php b/src/Step/ValidatorStep.php index cd4e9f7..3d847c5 100644 --- a/src/Step/ValidatorStep.php +++ b/src/Step/ValidatorStep.php @@ -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;