function it_can_compare_size() { $higherPrice = Price::fromString('130', Currency::fromString('EUR')); $this->isLessThan($higherPrice)->shouldBe(true); $lowerPrice = Price::fromString('110', Currency::fromString('EUR')); $this->isLessThan($lowerPrice)->shouldBe(false); }
function it_can_have_many_rates() { $price = Price::fromString('12.50', Currency::fromString('EUR')); $this->addRate(null, $price, 1); $this->getRates()->shouldHaveCount(2); $dateRange = RentalPeriod::fromDateTime(new \DateTime('2014-07-01'), new \DateTime('2014-07-07')); $this->addRate($dateRange, $price, 1); $this->getRates()->shouldHaveCount(3); }
function it_calculates_a_subtotal_of_line_items() { $rate = new Rate(null, Price::fromString('12.12', Currency::fromString('EUR')), 1); $this->add(RateQuoteLineItem::make($rate, 3)); /** @var Price $subtotal */ $subtotal = $this->getSubTotal(); $subtotal->shouldHaveType('Rental\\Price'); $subtotal->getValue()->shouldBe(36.36); }
/** * @return RentalQuery */ private function getQuery() { $price = Price::fromString('1', Currency::fromString('EUR')); $baseRate = new Rate(null, $price, 1); $equipment = new Equipment('Truck', $baseRate); // 38 days $queryPeriod = RentalPeriod::fromDateTime(new \DateTime('2014-08-01'), new \DateTime('2014-09-07')); $query = new RentalQuery($equipment, $queryPeriod); return $query; }
function it_gets_price_for_day_count_with_multi_day_rates() { $dateRange = RentalPeriod::fromDateTime(new \DateTime('2014-07-01'), new \DateTime('2014-07-07')); $price = Price::fromString(70, Currency::fromString('EUR')); $this->beConstructedWith($dateRange, $price, 7); $this->getPriceForDays(1)->shouldHaveType('Rental\\Price'); $this->getPriceForDays(1)->getValue()->shouldBe(70); $this->getPriceForDays(7)->getValue()->shouldBe(70); $this->getPriceForDays(8)->getValue()->shouldBe(140); $this->getPriceForDays(9)->getValue()->shouldBe(140); }
function it_has_rates_that_overlap_with_rental_period() { $this->getApplicableRates()->shouldHaveCount(1); $this->equipment->addRate(null, Price::fromString('11', Currency::fromString('EUR')), 1); $this->getApplicableRates()->shouldHaveCount(2); $this->equipment->addRate(RentalPeriod::fromDateTime(new \DateTime('2014-07-05'), new \DateTime('2014-07-10')), Price::fromString('11', Currency::fromString('EUR')), 1); $this->getApplicableRates()->shouldHaveCount(3); $this->equipment->addRate(RentalPeriod::fromDateTime(new \DateTime('2014-07-08'), new \DateTime('2014-07-10')), Price::fromString('11', Currency::fromString('EUR')), 1); $this->getApplicableRates()->shouldHaveCount(3); $this->equipment->addRate(RentalPeriod::fromDateTime(new \DateTime('2014-06-08'), new \DateTime('2014-06-30')), Price::fromString('11', Currency::fromString('EUR')), 1); $this->getApplicableRates()->shouldHaveCount(3); }
private function buildEquipment() { $price = Price::fromString('12', Currency::fromString('EUR')); $baseRate = new Rate(null, $price, 1); $equipment = new Equipment('Truck', $baseRate); // first rate $rentalPeriod = RentalPeriod::fromDateTime(new \DateTime('2014-06-01'), new \DateTime('2014-06-07')); $equipment->addRate($rentalPeriod, Price::fromString('10', Currency::fromString('EUR')), 1); // second rate $rentalPeriod = RentalPeriod::fromDateTime(new \DateTime('2014-07-01'), new \DateTime('2014-07-07')); $equipment->addRate($rentalPeriod, Price::fromString('10', Currency::fromString('EUR')), 2); return $equipment; }
function it_returns_rate_quotes_created_by_the_calculators() { $price = Price::fromString('1', Currency::fromString('EUR')); $baseRate = new Rate(null, $price, 1); $equipment = new Equipment('Truck', $baseRate); // 38 days $queryPeriod = RentalPeriod::fromDateTime(new \DateTime('2014-08-01'), new \DateTime('2014-09-07')); $query = new RentalQuery($equipment, $queryPeriod); $this->addCalculator(new SingleRateRateQuoteCalculator()); $quotes = $this->getQuotesFor($query); $quote = $quotes[0]; $quote->shouldHaveType('Rental\\RateQuote'); // 38 days * 1 eur $price = Price::fromString('38', Currency::fromString('EUR')); $quote->getSubTotal()->equals($price)->shouldBe(true); }
function it_compares_currencies_for_equality() { $sameCurrency = Currency::fromString('EUR'); $this->equals($sameCurrency)->shouldBe(true); }
/** * @return static */ private function buildPrice() { $price = Price::fromString('12', Currency::fromString('EUR')); return $price; }
function it_finds_a_daily_rate_price_from_date_range_rate() { // Date Range daily rate supplied $dailyPrice = Price::fromString('10', Currency::fromString('EUR')); $equipment = new Equipment('Jack Hammer', new Rate(null, $dailyPrice, 1)); $rentalQuery = new RentalQuery($equipment, RentalPeriod::fromDateTime(new \DateTime('2014-07-01'), new \DateTime('2014-07-07'), 1)); $quotes = $this->getQuotesFor($rentalQuery); $quote = $quotes[0]; /** @var RateQuote $quote */ $quote->getLineItems()->shouldHaveCount(1); $lineItems = $quote->getLineItems(); /** @var RateQuoteLineItem $lineItem */ $lineItem = $lineItems[0]; $lineItem->getRate()->getPrice()->equals($dailyPrice); ////////// $tempPrice = Price::fromString('8', Currency::fromString('EUR')); $equipment->addRate(RentalPeriod::fromDateTime(new \DateTime('2014-07-04'), new \DateTime('2014-07-10')), $tempPrice, 1); $quotes = $this->getQuotesFor($rentalQuery); $quote = $quotes[0]; /** @var RateQuote $quote */ $quote->getLineItems()->shouldHaveCount(1); $lineItems = $quote->getLineItems(); /** @var RateQuoteLineItem $lineItem */ $lineItem = $lineItems[0]; $lineItem->getRate()->getPrice()->equals($tempPrice); }