forked from exercism/php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccountTest.php
More file actions
227 lines (208 loc) · 6.44 KB
/
Copy pathBankAccountTest.php
File metadata and controls
227 lines (208 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
declare(strict_types=1);
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
class BankAccountTest extends TestCase
{
public static function setUpBeforeClass(): void
{
require_once 'BankAccount.php';
}
/**
* uuid: 983a1528-4ceb-45e5-8257-8ce01aceb5ed
*/
#[TestDox('Newly opened account has zero balance')]
public function testNewlyOpenedAccountHasZeroBalance(): void
{
$subject = new BankAccount();
$subject->open();
$this->assertEquals(0, $subject->balance());
}
/**
* uuid: e88d4ec3-c6bf-4752-8e59-5046c44e3ba7
*/
#[TestDox('Single deposit')]
public function testSingleDeposit(): void
{
$subject = new BankAccount();
$subject->open();
$subject->deposit(100);
$this->assertEquals(100, $subject->balance());
}
/**
* uuid: 3d9147d4-63f4-4844-8d2b-1fee2e9a2a0d
*/
#[TestDox('Multiple deposits')]
public function testMultipleDeposits(): void
{
$subject = new BankAccount();
$subject->open();
$subject->deposit(100);
$subject->deposit(50);
$this->assertEquals(150, $subject->balance());
}
/**
* uuid: 08f1af07-27ae-4b38-aa19-770bde558064
*/
#[TestDox('Withdraw once')]
public function testWithdrawOnce(): void
{
$subject = new BankAccount();
$subject->open();
$subject->deposit(100);
$subject->withdraw(75);
$this->assertEquals(25, $subject->balance());
}
/**
* uuid: 6f6d242f-8c31-4ac6-8995-a90d42cad59f
*/
#[TestDox('Withdraw twice')]
public function testWithdrawTwice(): void
{
$subject = new BankAccount();
$subject->open();
$subject->deposit(100);
$subject->withdraw(80);
$subject->withdraw(20);
$this->assertEquals(0, $subject->balance());
}
/**
* uuid: 45161c94-a094-4c77-9cec-998b70429bda
*/
#[TestDox('Can do multiple operations sequentially')]
public function testCanDoMultipleOperationsSequentially(): void
{
$subject = new BankAccount();
$subject->open();
$subject->deposit(100);
$subject->deposit(110);
$subject->withdraw(200);
$subject->deposit(60);
$subject->withdraw(50);
$this->assertEquals(20, $subject->balance());
}
/**
* uuid: f9facfaa-d824-486e-8381-48832c4bbffd
*/
#[TestDox('Cannot check balance of closed account')]
public function testCannotCheckBalanceOfClosedAccount(): void
{
$subject = new BankAccount();
$subject->open();
$subject->close();
$this->expectException(Exception::class);
$this->expectExceptionMessage('account not open');
$subject->balance();
}
/**
* uuid: 7a65ba52-e35c-4fd2-8159-bda2bde6e59c
*/
#[TestDox('Cannot deposit into closed account')]
public function testCannotDepositIntoClosedAccount(): void
{
$subject = new BankAccount();
$subject->open();
$subject->close();
$this->expectException(Exception::class);
$this->expectExceptionMessage('account not open');
$subject->deposit(50);
}
/**
* uuid: a0a1835d-faae-4ad4-a6f3-1fcc2121380b
*/
#[TestDox('Cannot deposit into unopened account')]
public function testCannotDepositIntoUnopenedAccount(): void
{
$subject = new BankAccount();
$this->expectException(Exception::class);
$this->expectExceptionMessage('account not open');
$subject->deposit(50);
}
/**
* uuid: 570dfaa5-0532-4c1f-a7d3-0f65c3265608
*/
#[TestDox('Cannot withdraw from closed account')]
public function testCannotWithdrawFromClosedAccount(): void
{
$subject = new BankAccount();
$subject->open();
$subject->close();
$this->expectException(Exception::class);
$this->expectExceptionMessage('account not open');
$subject->withdraw(50);
}
/**
* uuid: c396d233-1c49-4272-98dc-7f502dbb9470
*/
#[TestDox('Cannot close an account that was not opened')]
public function testCannotCloseAnAccountThatWasNotOpened(): void
{
$subject = new BankAccount();
$this->expectException(Exception::class);
$this->expectExceptionMessage('account not open');
$subject->close();
}
/**
* uuid: c06f534f-bdc2-4a02-a388-1063400684de
*/
#[TestDox('Cannot open an already opened account')]
public function testCannotOpenAnAlreadyOpenedAccount(): void
{
$subject = new BankAccount();
$subject->open();
$this->expectException(Exception::class);
$this->expectExceptionMessage('account already open');
$subject->open();
}
/**
* uuid: 0722d404-6116-4f92-ba3b-da7f88f1669c
*/
#[TestDox('Reopened account does not retain balance')]
public function testReopenedAccountDoesNotRetainBalance(): void
{
$subject = new BankAccount();
$subject->open();
$subject->deposit(50);
$subject->close();
$subject->open();
$this->assertEquals(0, $subject->balance());
}
/**
* uuid: ec42245f-9361-4341-8231-a22e8d19c52f
*/
#[TestDox('Cannot withdraw more than deposited')]
public function testCannotWithdrawMoreThanDeposited(): void
{
$subject = new BankAccount();
$subject->open();
$subject->deposit(25);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('amount must be less than balance');
$subject->withdraw(50);
}
/**
* uuid: 4f381ef8-10ef-4507-8e1d-0631ecc8ee72
*/
#[TestDox('Cannot withdraw negative')]
public function testCannotWithdrawNegative(): void
{
$subject = new BankAccount();
$subject->open();
$subject->deposit(100);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('amount must be greater than 0');
$subject->withdraw(-50);
}
/**
* uuid: d45df9ea-1db0-47f3-b18c-d365db49d938
*/
#[TestDox('Cannot deposit negative')]
public function testCannotDepositNegative(): void
{
$subject = new BankAccount();
$subject->open();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('amount must be greater than 0');
$subject->deposit(-50);
}
}