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
11use PHPUnit\Framework\TestCase;
12
13class BankAccountTest extends TestCase
14{
15    private $ba;
16
17    protected function setUp()
18    {
19        $this->ba = new BankAccount;
20    }
21
22    public function testBalanceIsInitiallyZero()
23    {
24        $ba = new BankAccount;
25
26        $balance = $ba->getBalance();
27
28        $this->assertEquals(0, $balance);
29    }
30
31    public function testBalanceCannotBecomeNegative()
32    {
33        try {
34            $this->ba->withdrawMoney(1);
35        } catch (BankAccountException $e) {
36            $this->assertEquals(0, $this->ba->getBalance());
37
38            return;
39        }
40
41        $this->fail();
42    }
43
44    public function testBalanceCannotBecomeNegative2()
45    {
46        try {
47            $this->ba->depositMoney(-1);
48        } catch (BankAccountException $e) {
49            $this->assertEquals(0, $this->ba->getBalance());
50
51            return;
52        }
53
54        $this->fail();
55    }
56}
57