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); }
/** * @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_checks_if_it_overlaps_with_a_range() { $internal = RentalPeriod::fromDateTime(new \DateTime('2014-07-03'), new \DateTime('2014-07-05')); $this->overlapsWithRange($internal)->shouldBe(true); $before = RentalPeriod::fromDateTime(new \DateTime('2014-06-03'), new \DateTime('2014-06-30')); $this->overlapsWithRange($before)->shouldBe(false); $after = RentalPeriod::fromDateTime(new \DateTime('2014-07-10'), new \DateTime('2014-07-30')); $this->overlapsWithRange($after)->shouldBe(false); $startDuring = RentalPeriod::fromDateTime(new \DateTime('2014-07-04'), new \DateTime('2014-07-30')); $this->overlapsWithRange($startDuring)->shouldBe(true); $endDuring = RentalPeriod::fromDateTime(new \DateTime('2014-06-10'), new \DateTime('2014-07-03')); $this->overlapsWithRange($endDuring)->shouldBe(true); $encapsulates = RentalPeriod::fromDateTime(new \DateTime('2014-06-10'), new \DateTime('2014-08-03')); $this->overlapsWithRange($encapsulates)->shouldBe(true); }
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_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); }