1<?php 2/* 3 * This file is part of PHPUnit. 4 * 5 * (c) Sebastian Bergmann <sebastian@phpunit.de> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11/** 12 * Tests for the BankAccount class. 13 * 14 */ 15class BankAccountTest extends PHPUnit_Framework_TestCase 16{ 17 protected $ba; 18 19 protected function setUp() 20 { 21 $this->ba = new BankAccount; 22 } 23 24 /** 25 * @covers BankAccount::getBalance 26 * @group balanceIsInitiallyZero 27 * @group specification 28 */ 29 public function testBalanceIsInitiallyZero() 30 { 31 /* @Given a fresh bank account */ 32 $ba = new BankAccount; 33 34 /* @When I ask it for its balance */ 35 $balance = $ba->getBalance(); 36 37 /* @Then I should get 0 */ 38 $this->assertEquals(0, $balance); 39 } 40 41 /** 42 * @covers BankAccount::withdrawMoney 43 * @group balanceCannotBecomeNegative 44 * @group specification 45 */ 46 public function testBalanceCannotBecomeNegative() 47 { 48 try { 49 $this->ba->withdrawMoney(1); 50 } catch (BankAccountException $e) { 51 $this->assertEquals(0, $this->ba->getBalance()); 52 53 return; 54 } 55 56 $this->fail(); 57 } 58 59 /** 60 * @covers BankAccount::depositMoney 61 * @group balanceCannotBecomeNegative 62 * @group specification 63 */ 64 public function testBalanceCannotBecomeNegative2() 65 { 66 try { 67 $this->ba->depositMoney(-1); 68 } catch (BankAccountException $e) { 69 $this->assertEquals(0, $this->ba->getBalance()); 70 71 return; 72 } 73 74 $this->fail(); 75 } 76 77 /* 78 * @covers BankAccount::getBalance 79 * @covers BankAccount::depositMoney 80 * @covers BankAccount::withdrawMoney 81 * @group balanceCannotBecomeNegative 82 */ 83 /* 84 public function testDepositingAndWithdrawingMoneyWorks() 85 { 86 $this->assertEquals(0, $this->ba->getBalance()); 87 $this->ba->depositMoney(1); 88 $this->assertEquals(1, $this->ba->getBalance()); 89 $this->ba->withdrawMoney(1); 90 $this->assertEquals(0, $this->ba->getBalance()); 91 } 92 */ 93} 94