Beispiel #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));
 }
Beispiel #2
0
 public function testComputeWithPercentExceptions($operation, $left, $right)
 {
     $this->if($price = new TestedPrice($left))->assert->exception(function () use($price, $right, $operation) {
         $price->compute($operation, new TestedPrice($right));
     })->isInstanceOf('\\LogicException')->message->contains('Unsupported operator');
 }