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']); }
/** * @param ProductValueInterface $value * * @return ClassMetadata */ protected function createMetadata(ProductValueInterface $value) { $class = ClassUtils::getClass($value); $attribute = $value->getAttribute(); $cacheKey = $attribute->getCode(); if (!isset($this->attrConstraintsCache[$cacheKey])) { $metadata = $this->factory->createMetadata($class); foreach ($this->guesser->guessConstraints($attribute) as $constraint) { $this->addConstraint($metadata, $constraint, $attribute); } $this->attrConstraintsCache[$cacheKey] = $metadata; } return $this->attrConstraintsCache[$cacheKey]; }