From 384de897436daee7ce30b9d554355761d20df609 Mon Sep 17 00:00:00 2001 From: datbt-2563 Date: Tue, 12 Jul 2022 10:06:13 +0700 Subject: [PATCH 1/2] chore: fix --- src/Entity/TicketInfo.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Entity/TicketInfo.php b/src/Entity/TicketInfo.php index 22a7d0d..db1a79f 100644 --- a/src/Entity/TicketInfo.php +++ b/src/Entity/TicketInfo.php @@ -6,9 +6,9 @@ class TicketInfo { - public DateTime $bookingDate; - public int $gender; - public int $age; + public $bookingDate; + public $gender; + public $age; public function __construct(DateTime $bookingDate, int $gender, int $age) { From 7b2937ed726b53387470da9a8e6621d5a8889b4c Mon Sep 17 00:00:00 2001 From: datbt-2563 Date: Tue, 12 Jul 2022 10:10:09 +0700 Subject: [PATCH 2/2] feat: ut for bank service --- tests/Unit/BankServiceTest.php | 203 +++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 tests/Unit/BankServiceTest.php diff --git a/tests/Unit/BankServiceTest.php b/tests/Unit/BankServiceTest.php new file mode 100644 index 0000000..6f1882c --- /dev/null +++ b/tests/Unit/BankServiceTest.php @@ -0,0 +1,203 @@ +calculateFee($card); + + $this->assertEquals($bankService::NORMAL_FEE, $fee); + } + + public function testNoVIPCardInWeekendAtChargeTimePeriod() + { + $card = new Card("no-vip", false); + $testDate = Carbon::create(2022, 7, 10, 9, 20); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testNoVIPCardInHoliDayAtChargeTimePeriod() + { + $card = new Card("no-vip", false); + $testDate = Carbon::create(2022, 4, 30, 9, 20); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testNoVIPCardInHoliDayAndWeekendAtChargeTimePeriod() + { + $card = new Card("no-vip", false); + $testDate = Carbon::create(2022, 5, 1, 9, 20); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testNoVIPCardInNormalDayAtFreeTimePeriod() + { + $card = new Card("no-vip", false); + $testDate = Carbon::create(2022, 7, 12, 8, 0); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NORMAL_FEE, $fee); + } + + public function testNoVIPCardInWeekendAtFreeTimePeriod() + { + $card = new Card("no-vip", false); + $testDate = Carbon::create(2022, 7, 10, 8, 0); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testNoVIPCardInHoliDayAtFreeTimePeriod() + { + $card = new Card("no-vip", false); + $testDate = Carbon::create(2022, 4, 30, 8, 0); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testNoVIPCardInHoliDayAndWeekendAtFreeTimePeriod() + { + $card = new Card("no-vip", false); + $testDate = Carbon::create(2022, 5, 1, 8, 0); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testVIPCardInNormalDayAtChargeTimePeriod() + { + $card = new Card("vip", true); + $testDate = Carbon::create(2022, 7, 12, 9, 20); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NORMAL_FEE, $fee); + } + + public function testVIPCardInWeekendAtChargeTimePeriod() + { + $card = new Card("vip", true); + $testDate = Carbon::create(2022, 7, 10, 9, 20); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testVIPCardInHoliDayAtChargeTimePeriod() + { + $card = new Card("vip", true); + $testDate = Carbon::create(2022, 4, 30, 9, 20); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testVIPCardInHoliDayAndWeekendAtChargeTimePeriod() + { + $card = new Card("vip", true); + $testDate = Carbon::create(2022, 5, 1, 9, 20); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testVIPCardInNormalDayAtFreeTimePeriod() + { + $card = new Card("vip", true); + $testDate = Carbon::create(2022, 7, 12, 8, 0); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NORMAL_FEE, $fee); + } + + public function testVIPCardInWeekendAtFreeTimePeriod() + { + $card = new Card("vip", true); + $testDate = Carbon::create(2022, 7, 10, 8, 0); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testVIPCardInHoliDayAtFreeTimePeriod() + { + $card = new Card("vip", true); + $testDate = Carbon::create(2022, 4, 30, 8, 0); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } + + public function testVIPCardInHoliDayAndWeekendAtFreeTimePeriod() + { + $card = new Card("vip", true); + $testDate = Carbon::create(2022, 5, 1, 8, 0); + Carbon::setTestNow($testDate); + + $bankService = new BankService(); + $fee = $bankService->calculateFee($card); + + $this->assertEquals($bankService::NO_FEE, $fee); + } +}