Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function calculate($base, TaxRateInterface $rate)
 {
     if ($rate->isIncludedInPrice()) {
         return (int) round($base - $base / (1 + $rate->getAmount()));
     }
     return (int) round($base * $rate->getAmount());
 }
Ejemplo n.º 2
0
 function it_calculates_correct_tax_for_given_base_if_rate_is_included_in_price(TaxRateInterface $rate)
 {
     $rate->isIncludedInPrice()->willReturn(true);
     $rate->getAmount()->willReturn(0.23);
     $this->calculate(10000, $rate)->shouldReturn(1870);
     $rate->getAmount()->willReturn(0.2);
     $this->calculate(315, $rate)->shouldReturn(53);
 }
Ejemplo n.º 3
0
 function it_should_delegate_calculation_to_a_correct_calculator($calculator, TaxRateInterface $rate)
 {
     $rate->getCalculator()->willReturn('default');
     $calculator->calculate(100, $rate)->shouldBeCalled()->willReturn(23);
     $this->calculate(100, $rate)->shouldReturn(23);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function calculate($base, TaxRateInterface $rate)
 {
     /** @var CalculatorInterface $calculator */
     $calculator = $this->calculatorsRegistry->get($rate->getCalculator());
     return $calculator->calculate($base, $rate);
 }
Ejemplo n.º 5
0
 function it_should_complain_if_correct_calculator_doesnt_exist_for_given_rate(TaxRateInterface $rate, CalculatorInterface $calculator)
 {
     $this->registerCalculator('default', $calculator);
     $rate->getCalculator()->willReturn('custom');
     $this->shouldThrow('InvalidArgumentException')->duringCalculate(100, $rate);
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function calculate($base, TaxRateInterface $rate)
 {
     $calculator = $this->getCalculator($rate->getCalculator());
     return $calculator->calculate($base, $rate);
 }