|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kingsquare\Banking; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @author Kingsquare ([email protected]) |
|
7
|
|
|
* @copyright Copyright (c) Kingsquare BV (http://www.kingsquare.nl) |
|
8
|
|
|
*/ |
|
9
|
|
|
class TransactionTest extends \PHPUnit_Framework_TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testAccountAssesor() |
|
12
|
|
|
{ |
|
13
|
|
|
$expected = '62.90.64.393'; |
|
14
|
|
|
$transaction = new Transaction(); |
|
15
|
|
|
$transaction->setAccount($expected); |
|
16
|
|
|
|
|
17
|
|
|
$this->assertEquals($expected, $transaction->getAccount()); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testAccountNameAssesor() |
|
21
|
|
|
{ |
|
22
|
|
|
$expected = 'Kingsquare BV'; |
|
23
|
|
|
$transaction = new Transaction(); |
|
24
|
|
|
$transaction->setAccountName($expected); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertEquals($expected, $transaction->getAccountName()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testPriceAssesor() |
|
30
|
|
|
{ |
|
31
|
|
|
$expected = '6250'; |
|
32
|
|
|
$transaction = new Transaction(); |
|
33
|
|
|
$transaction->setPrice($expected); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
$this->assertEquals($expected, $transaction->getPrice()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testRelativePriceAssesor() |
|
39
|
|
|
{ |
|
40
|
|
|
$expected = '6250'; |
|
41
|
|
|
$transaction = new Transaction(); |
|
42
|
|
|
$transaction->setPrice($expected); |
|
|
|
|
|
|
43
|
|
|
$transaction->setDebitCredit('C'); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertEquals($expected, $transaction->getRelativePrice()); |
|
46
|
|
|
|
|
47
|
|
|
$transaction->setDebitCredit('D'); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertEquals($expected * -1, $transaction->getRelativePrice()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testDebitCreditAssesorDebit() |
|
53
|
|
|
{ |
|
54
|
|
|
$expected = 'D'; |
|
55
|
|
|
$transaction = new Transaction(); |
|
56
|
|
|
$transaction->setDebitCredit($expected); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertEquals($expected, $transaction->getDebitCredit()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testDebitCreditAssesorCredit() |
|
62
|
|
|
{ |
|
63
|
|
|
$expected = 'C'; |
|
64
|
|
|
$transaction = new Transaction(); |
|
65
|
|
|
$transaction->setDebitCredit($expected); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertEquals($expected, $transaction->getDebitCredit()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testDescriptionAssesor() |
|
71
|
|
|
{ |
|
72
|
|
|
$expected = 'This is a description'; |
|
73
|
|
|
$transaction = new Transaction(); |
|
74
|
|
|
$transaction->setDescription($expected); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertEquals($expected, $transaction->getDescription()); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testValueTimestampAssesor() |
|
80
|
|
|
{ |
|
81
|
|
|
$expected = time(); |
|
82
|
|
|
$transaction = new Transaction(); |
|
83
|
|
|
$transaction->setValueTimestamp($expected); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertEquals($expected, $transaction->getValueTimestamp()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testEntryTimestampAssesor() |
|
89
|
|
|
{ |
|
90
|
|
|
$expected = time(); |
|
91
|
|
|
$transaction = new Transaction(); |
|
92
|
|
|
$transaction->setEntryTimestamp($expected); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertEquals($expected, $transaction->getEntryTimestamp()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testTransactionCodeAssesor() |
|
98
|
|
|
{ |
|
99
|
|
|
$expected = '13G'; |
|
100
|
|
|
$transaction = new Transaction(); |
|
101
|
|
|
$transaction->setTransactionCode($expected); |
|
102
|
|
|
|
|
103
|
|
|
$this->assertEquals($expected, $transaction->getTransactionCode()); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @depends testValueTimestampAssesor |
|
108
|
|
|
*/ |
|
109
|
|
|
public function testGetValueTimestampWithFormat() |
|
110
|
|
|
{ |
|
111
|
|
|
$expected = '2012-01-01 12:00'; |
|
112
|
|
|
$transaction = new Transaction(); |
|
113
|
|
|
$transaction->setValueTimestamp(strtotime($expected)); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertEquals($expected, $transaction->getValueTimestamp('Y-m-d H:i')); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @depends testEntryTimestampAssesor |
|
120
|
|
|
*/ |
|
121
|
|
|
public function testGetEntryTimestampWithFormat() |
|
122
|
|
|
{ |
|
123
|
|
|
$expected = '2012-01-01 12:00'; |
|
124
|
|
|
$transaction = new Transaction(); |
|
125
|
|
|
$transaction->setEntryTimestamp(strtotime($expected)); |
|
126
|
|
|
|
|
127
|
|
|
$this->assertEquals($expected, $transaction->getEntryTimestamp('Y-m-d H:i')); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function testIsDebit() |
|
131
|
|
|
{ |
|
132
|
|
|
$transaction = new Transaction(); |
|
133
|
|
|
$transaction->setDebitCredit('D'); |
|
134
|
|
|
|
|
135
|
|
|
$this->assertTrue($transaction->isDebit()); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function testIsCredit() |
|
139
|
|
|
{ |
|
140
|
|
|
$transaction = new Transaction(); |
|
141
|
|
|
$transaction->setDebitCredit('C'); |
|
142
|
|
|
|
|
143
|
|
|
$this->assertTrue($transaction->isCredit()); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function testJsonSerialization() |
|
147
|
|
|
{ |
|
148
|
|
|
$expected = '{"account":"123123","accountName":"Kingsquare BV","price":110,"debitcredit":"D","cancellation":false,'. |
|
149
|
|
|
'"description":"test","valueTimestamp":1231,"entryTimestamp":1234,"transactionCode":"13G"}'; |
|
150
|
|
|
|
|
151
|
|
|
$params = [ |
|
152
|
|
|
'account' => '123123', |
|
153
|
|
|
'accountName' => 'Kingsquare BV', |
|
154
|
|
|
'price' => 110.0, |
|
155
|
|
|
'debitcredit' => Transaction::DEBIT, |
|
156
|
|
|
'cancellation' => false, |
|
157
|
|
|
'description' => 'test', |
|
158
|
|
|
'valueTimestamp' => 1231, |
|
159
|
|
|
'entryTimestamp' => 1234, |
|
160
|
|
|
'transactionCode' => '13G', |
|
161
|
|
|
]; |
|
162
|
|
|
$statement = new Transaction(); |
|
163
|
|
|
foreach ($params as $key => $value) { |
|
164
|
|
|
$statement->{'set'.$key}($value); |
|
165
|
|
|
} |
|
166
|
|
|
$this->assertSame($expected, json_encode($statement)); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|