No Description

BankAccountTest.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. require_once 'BankAccount.php';
  3. use PHPUnit\Framework\TestCase;
  4. class BankAccountTest extends TestCase
  5. {
  6. protected $ba;
  7. protected function setUp()
  8. {
  9. $this->ba = new BankAccount;
  10. }
  11. /**
  12. * @covers BankAccount::getBalance
  13. */
  14. public function testBalanceIsInitiallyZero()
  15. {
  16. $this->assertEquals(0, $this->ba->getBalance());
  17. }
  18. /**
  19. * @covers BankAccount::withdrawMoney
  20. */
  21. public function testBalanceCannotBecomeNegative()
  22. {
  23. try {
  24. $this->ba->withdrawMoney(1);
  25. } catch (RuntimeException $e) {
  26. $this->assertEquals(0, $this->ba->getBalance());
  27. return;
  28. }
  29. $this->fail();
  30. }
  31. /**
  32. * @covers BankAccount::depositMoney
  33. */
  34. public function testBalanceCannotBecomeNegative2()
  35. {
  36. try {
  37. $this->ba->depositMoney(-1);
  38. } catch (RuntimeException $e) {
  39. $this->assertEquals(0, $this->ba->getBalance());
  40. return;
  41. }
  42. $this->fail();
  43. }
  44. /**
  45. * @covers BankAccount::getBalance
  46. * @covers BankAccount::depositMoney
  47. * @covers BankAccount::withdrawMoney
  48. */
  49. public function testDepositWithdrawMoney()
  50. {
  51. $this->assertEquals(0, $this->ba->getBalance());
  52. $this->ba->depositMoney(1);
  53. $this->assertEquals(1, $this->ba->getBalance());
  54. $this->ba->withdrawMoney(1);
  55. $this->assertEquals(0, $this->ba->getBalance());
  56. }
  57. }