/** * Validates the value to be greater or equal than the constraint value. * * @param Money $value Value * @param Constraint $constraint Constraint * * @return null */ public function validate($value, Constraint $constraint) { if (null === $value) { return null; } if (!$value instanceof Money) { throw new UnexpectedTypeException($value, 'Elcodi\\Component\\Currency\\Entity\\Money'); } $minimumMoney = Money::create($constraint->value, $value->getCurrency()); if ($value->isLessThan($minimumMoney)) { $this->context->buildViolation($constraint->message)->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING))->setParameter('{{ compared_value }}', $this->formatValue($minimumMoney, self::OBJECT_TO_STRING))->setParameter('{{ compared_value_type }}', $this->formatTypeOf($minimumMoney))->addViolation(); } }
/** * @covers \Elcodi\Component\Currency\Entity\Money::getCurrency */ public function testGetCurrency() { $this->assertInstanceOf('\\Elcodi\\Component\\Currency\\Entity\\Currency', $this->oneHundredDollars->getCurrency()); }