BankAccountTest.php 1.5 KB

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