3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Tests for the BankAccount class.
14 * @since Class available since Release 2.3.0
16 class BankAccountTest extends PHPUnit_Framework_TestCase
20 protected function setUp()
22 $this->ba = new BankAccount;
26 * @covers BankAccount::getBalance
27 * @group balanceIsInitiallyZero
28 * @group specification
30 public function testBalanceIsInitiallyZero()
32 $this->assertEquals(0, $this->ba->getBalance());
36 * @covers BankAccount::withdrawMoney
37 * @group balanceCannotBecomeNegative
38 * @group specification
40 public function testBalanceCannotBecomeNegative()
43 $this->ba->withdrawMoney(1);
44 } catch (BankAccountException $e) {
45 $this->assertEquals(0, $this->ba->getBalance());
54 * @covers BankAccount::depositMoney
55 * @group balanceCannotBecomeNegative
56 * @group specification
58 public function testBalanceCannotBecomeNegative2()
61 $this->ba->depositMoney(-1);
62 } catch (BankAccountException $e) {
63 $this->assertEquals(0, $this->ba->getBalance());
72 * @covers BankAccount::getBalance
73 * @covers BankAccount::depositMoney
74 * @covers BankAccount::withdrawMoney
75 * @group balanceCannotBecomeNegative
78 public function testDepositingAndWithdrawingMoneyWorks()
80 $this->assertEquals(0, $this->ba->getBalance());
81 $this->ba->depositMoney(1);
82 $this->assertEquals(1, $this->ba->getBalance());
83 $this->ba->withdrawMoney(1);
84 $this->assertEquals(0, $this->ba->getBalance());