/** * Returns an array of constraints for a given attribute * * @param AttributeInterface $attribute * * @return string */ protected function getAttributeConstraints(AttributeInterface $attribute) { $code = $attribute->getCode(); if (!isset($this->constraints[$code])) { if ($this->constraintGuesser->supportAttribute($attribute)) { $this->constraints[$code] = $this->constraintGuesser->guessConstraints($attribute); } else { $this->constraints[$code] = []; } } return $this->constraints[$code]; }
function it_can_guess_constraints(AttributeInterface $attribute, ConstraintGuesserInterface $guesserFoo, ConstraintGuesserInterface $guesserBar, ConstraintGuesserInterface $guesserBaz) { $guesserFoo->guessConstraints($attribute)->willReturn(['foo']); $guesserBar->guessConstraints($attribute)->willReturn(['bar']); $guesserBaz->guessConstraints($attribute)->willReturn(['baz']); $guesserFoo->supportAttribute($attribute)->willReturn(true); $guesserBar->supportAttribute($attribute)->willReturn(false); $guesserBaz->supportAttribute($attribute)->willReturn(true); $this->addConstraintGuesser($guesserFoo); $this->addConstraintGuesser($guesserBar); $this->addConstraintGuesser($guesserBaz); $this->guessConstraints($attribute)->shouldReturn(['foo', 'baz']); }