Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/unittest bank service #5

Open
wants to merge 2 commits into
base: exercises
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Entity/TicketInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
203 changes: 203 additions & 0 deletions tests/Unit/BankServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<?php

namespace Tests;

use PHPUnit\Framework\TestCase;
use Carbon\Carbon;
use StdGroup\App\BankService;
use StdGroup\App\Entity\Card;

class BankServiceTest extends TestCase
{
public function testNoVIPCardInNormalDayAtChargeTimePeriod()
{
$card = new Card("no-vip", false);
$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 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);
}
}