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