1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kingsquare\Parser\Banking\Mt940\Engine\Triodos; |
4
|
|
|
|
5
|
|
|
use Kingsquare\Banking\Statement; |
6
|
|
|
use Kingsquare\Parser\Banking\Mt940\Engine\Triodos; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
class ParseTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Statement[] |
15
|
|
|
*/ |
16
|
|
|
private $statements; |
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$engine = new Triodos(); |
21
|
|
|
$engine->loadString(file_get_contents(__DIR__.'/sample')); |
22
|
|
|
$this->statements = $engine->parse(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testmultipleStatementsInASingleFile() |
26
|
|
|
{ |
27
|
|
|
$this->assertCount(2, $this->statements); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testBankFromStatement() |
31
|
|
|
{ |
32
|
|
|
/* @var Statement $statement */ |
33
|
|
|
foreach ($this->statements as $i => $statement) { |
34
|
|
|
$this->assertSame('Triodos', $statement->getBank()); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testAccountFromStatement() |
39
|
|
|
{ |
40
|
|
|
/* @var Statement $statement */ |
41
|
|
|
$known = [ |
42
|
|
|
'666666666', |
43
|
|
|
'999999999', |
44
|
|
|
]; |
45
|
|
|
foreach ($this->statements as $i => $statement) { |
46
|
|
|
$this->assertSame($known[$i], $statement->getAccount()); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testStartPriceFromStatement() |
51
|
|
|
{ |
52
|
|
|
/* @var Statement $statement */ |
53
|
|
|
$known = [ |
54
|
|
|
1000.0, |
55
|
|
|
950.12, |
56
|
|
|
]; |
57
|
|
|
foreach ($this->statements as $i => $statement) { |
58
|
|
|
$this->assertSame($known[$i], $statement->getStartPrice()); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testEndPriceFromStatement() |
63
|
|
|
{ |
64
|
|
|
/* @var Statement $statement */ |
65
|
|
|
$known = [ |
66
|
|
|
850.0, |
67
|
|
|
1009.14, |
68
|
|
|
]; |
69
|
|
|
foreach ($this->statements as $i => $statement) { |
70
|
|
|
$this->assertSame($known[$i], $statement->getEndPrice()); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testTimestampFromStatement() |
75
|
|
|
{ |
76
|
|
|
/* @var Statement $statement */ |
77
|
|
|
$known = [ |
78
|
|
|
'121123', |
79
|
|
|
'121123', |
80
|
|
|
]; |
81
|
|
|
foreach ($this->statements as $i => $statement) { |
82
|
|
|
$this->assertSame($known[$i], $statement->getStartTimestamp('ymd')); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testNumberFromStatement() |
87
|
|
|
{ |
88
|
|
|
/* @var Statement $statement */ |
89
|
|
|
foreach ($this->statements as $i => $statement) { |
90
|
|
|
$this->assertSame('1', $statement->getNumber()); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testParsesAllFoundStatements() |
95
|
|
|
{ |
96
|
|
|
list($first, $last) = $this->statements; |
97
|
|
|
|
98
|
|
|
$this->assertEquals('23-11-2012', $first->getStartTimestamp('d-m-Y')); |
99
|
|
|
$this->assertEquals('23-11-2012', $first->getEndTimestamp('d-m-Y')); |
100
|
|
|
$this->assertEquals(150, $first->getDeltaPrice()); |
101
|
|
|
|
102
|
|
|
$this->assertEquals('23-11-2012', $last->getStartTimestamp('d-m-Y')); |
103
|
|
|
$this->assertEquals('23-11-2012', $last->getEndTimestamp('d-m-Y')); |
104
|
|
|
$this->assertEquals(-59.02, $last->getDeltaPrice()); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|