diff --git a/src/Command/CalculateQuotePrice.php b/src/Command/CalculateQuotePrice.php index ece79d4..658e8a4 100644 --- a/src/Command/CalculateQuotePrice.php +++ b/src/Command/CalculateQuotePrice.php @@ -9,6 +9,8 @@ class CalculateQuotePrice public ?\DateTime $arrivalDate; + public ?int $guestCount = null; + public ?int $nightsCount = null; public function __construct() diff --git a/src/CommandHandler/CalculateQuotePriceHandler.php b/src/CommandHandler/CalculateQuotePriceHandler.php index 919c1e9..45b910f 100644 --- a/src/CommandHandler/CalculateQuotePriceHandler.php +++ b/src/CommandHandler/CalculateQuotePriceHandler.php @@ -18,6 +18,10 @@ public function __construct(QuotePriceCalculator $priceCalculator) public function __invoke(CalculateQuotePrice $command): void { - $command->amount = $this->priceCalculator->calculate($command->arrivalDate, $command->nightsCount); + $command->amount = $this->priceCalculator->calculate( + $command->arrivalDate, + $command->nightsCount, + $command->guestCount + ); } } diff --git a/src/Controller/QuotesController.php b/src/Controller/QuotesController.php index d8e53ff..ae099f6 100644 --- a/src/Controller/QuotesController.php +++ b/src/Controller/QuotesController.php @@ -37,6 +37,7 @@ public function index(Request $request): Response 'amount' => $command->amount, 'nights_count' => $command->nightsCount, 'arrival_date' => $command->arrivalDate, + 'guest_count' => $command->guestCount, ] ); } diff --git a/src/Form/CalculateQuotePriceForm.php b/src/Form/CalculateQuotePriceForm.php index 05e8d2d..c77227d 100644 --- a/src/Form/CalculateQuotePriceForm.php +++ b/src/Form/CalculateQuotePriceForm.php @@ -30,6 +30,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void [ 'label' => 'nights_count', ] + )->add( + 'guestCount', + IntegerType::class, + [ + 'label' => 'guest_count', + ] )->add( 'submit', SubmitType::class, diff --git a/src/Service/QuotePriceCalculator.php b/src/Service/QuotePriceCalculator.php index a45a96b..ad99226 100644 --- a/src/Service/QuotePriceCalculator.php +++ b/src/Service/QuotePriceCalculator.php @@ -12,7 +12,7 @@ public function __construct(PriceListFactory $priceListFactory) $this->priceListFactory = $priceListFactory; } - public function calculate(\DateTime $arrivalDate, int $nightsCount): float + public function calculate(\DateTime $arrivalDate, int $nightsCount, int $guestCount): float { if ($nightsCount <= 0) { throw new \Exception(); @@ -23,7 +23,7 @@ public function calculate(\DateTime $arrivalDate, int $nightsCount): float $pricePerNight = $priceList->getPricePerNight($arrivalDate); $discountPercentage = $this->getLongStayDiscountPercentage($nightsCount); - return $pricePerNight * $nightsCount * (1 - $discountPercentage); + return $pricePerNight * $nightsCount * $guestCount * (1 - $discountPercentage); } private function getLongStayDiscountPercentage(int $nightsCount): float diff --git a/templates/calculatedAmount.html.twig b/templates/calculatedAmount.html.twig index b07d198..b9e04f1 100644 --- a/templates/calculatedAmount.html.twig +++ b/templates/calculatedAmount.html.twig @@ -13,6 +13,9 @@
  • {{ 'nights_count'|trans }}: {{ nights_count }}
  • +
  • + {{ 'guest_count'|trans }}: {{ guest_count }} +
  • diff --git a/templates/index.html.twig b/templates/index.html.twig index be69250..1a0e811 100644 --- a/templates/index.html.twig +++ b/templates/index.html.twig @@ -6,12 +6,15 @@ {{ form_start(form) }}
    -
    +
    {{ form_row(form.arrivalDate) }}
    -
    +
    {{ form_row(form.nightsCount) }}
    +
    + {{ form_row(form.guestCount) }} +
    diff --git a/tests/Functional/QuoteTest.php b/tests/Functional/QuoteTest.php index a818b3d..6042969 100644 --- a/tests/Functional/QuoteTest.php +++ b/tests/Functional/QuoteTest.php @@ -24,6 +24,7 @@ public function it_calculates_quote_price() $form->setValues([ 'calculate_quote_price_form[arrivalDate]' => '17/11/2021', 'calculate_quote_price_form[nightsCount]' => '2', + 'calculate_quote_price_form[guestCount]' => '3', ]); $client->submit($form); diff --git a/tests/Integration/Service/QuotePriceCalculatorTest.php b/tests/Integration/Service/QuotePriceCalculatorTest.php index c543fa9..75707f5 100644 --- a/tests/Integration/Service/QuotePriceCalculatorTest.php +++ b/tests/Integration/Service/QuotePriceCalculatorTest.php @@ -20,11 +20,12 @@ public function it_calculates_reservation_price() $arrivalDate = new \DateTime('2021-06-01'); // In the high season $nightsCount = 2; + $guestCount = 3; // Action - $price = $SUT->calculate($arrivalDate, $nightsCount); + $price = $SUT->calculate($arrivalDate, $nightsCount, $guestCount); - // Expectations: 80€ * 2 nights * 1 (no discount) - $this->assertEquals(80 * 2, $price); + // Expectations: 80€ * 2 nights * 3 guests * 1 (no discount) + $this->assertEquals(80 * 2 * 3, $price); } } diff --git a/tests/Unit/Service/QuotePriceCalculatorTest.php b/tests/Unit/Service/QuotePriceCalculatorTest.php index a4c442d..7844dd5 100644 --- a/tests/Unit/Service/QuotePriceCalculatorTest.php +++ b/tests/Unit/Service/QuotePriceCalculatorTest.php @@ -31,14 +31,15 @@ public function it_calculates_reservation_price() $arrivalDate = new \DateTime('2021-06-01'); // In the high season $nightsCount = 2; + $guestCount = 3; // Expectation: price per night will be got from a PriceList object $priceListFactory->method('create')->willReturn($priceList); // Action - $price = $SUT->calculate($arrivalDate, $nightsCount); + $price = $SUT->calculate($arrivalDate, $nightsCount, $guestCount); - // Expectations: 80€ * 2 nights * 1 (no discount) - $this->assertEquals(80 * 2, $price); + // Expectations: 80€ * 2 nights * 3 guests * 1 (no discount) + $this->assertEquals(80 * 2 * 3, $price); } } diff --git a/translations/messages.en.yml b/translations/messages.en.yml index 41060dc..b85db06 100644 --- a/translations/messages.en.yml +++ b/translations/messages.en.yml @@ -6,3 +6,4 @@ footer_message: Demo project @ 2021 back: Back your_quote: Your quote total: Total +guest_count: Guest count diff --git a/translations/messages.it.yml b/translations/messages.it.yml index 490750a..5fd63bc 100644 --- a/translations/messages.it.yml +++ b/translations/messages.it.yml @@ -7,3 +7,4 @@ back: Indietro quote_amount: Importo del preventivo your_quote: Il tuo preventivo total: Totale +guest_count: Numero di ospiti