Esempio n. 1
0
 /**
  * @param string $operation operation
  * @param Price  $right     right
  *
  * @return Result
  */
 protected function computeWithPrice($operation, Price $right)
 {
     switch ($operation) {
         case Operation::MAJORATE:
             $value = $this->round($this->getValue() + $right->getValue());
             break;
         case Operation::MINORATE:
             $value = $this->round($this->getValue() - $right->getValue());
             break;
         default:
             throw new \LogicException(sprintf('Unsupported operator (%s) in operation: "%s %s %s".', $operation, $this, $operation, $right));
             break;
     }
     return new Result(new Price($value, $this->getCurrency(), $this->getFormatter()), new Price($this->round($this->getValue() - $value), $this->getCurrency(), $this->getFormatter()), sprintf('%s %s %s', $this, $operation, $right));
 }
Esempio n. 2
0
 public function testConstruct($value, $currencyCode, $expectedValue, $expectedCurrencyCode)
 {
     $this->if($price = new TestedPrice($value, $currencyCode))->phpFloat($price->getValue())->isIdenticalTo($expectedValue)->phpString($price->getCurrency())->isIdenticalTo($expectedCurrencyCode);
 }