1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kingsquare\Parser\Banking\Mt940\Engine\Rabo; |
4
|
|
|
|
5
|
|
|
use Kingsquare\Parser\Banking\Mt940\Engine\Rabo; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
class ParseTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Rabo |
14
|
|
|
*/ |
15
|
|
|
private $engine = null; |
16
|
|
|
|
17
|
|
|
protected function setUp() |
18
|
|
|
{ |
19
|
|
|
$this->engine = new Rabo(); |
20
|
|
|
$this->engine->loadString(file_get_contents(__DIR__.'/sample')); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testParseStatementBank() |
24
|
|
|
{ |
25
|
|
|
$method = new \ReflectionMethod($this->engine, 'parseStatementBank'); |
26
|
|
|
$method->setAccessible(true); |
27
|
|
|
$this->assertEquals('Rabo', $method->invoke($this->engine)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
View Code Duplication |
public function testParsesAllFoundStatements() |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$statements = $this->engine->parse(); |
33
|
|
|
|
34
|
|
|
$this->assertEquals(39, count($statements)); |
35
|
|
|
$first = $statements[0]; |
36
|
|
|
$last = end($statements); |
37
|
|
|
$this->assertEquals('06-01-2003', $first->getStartTimestamp('d-m-Y')); |
38
|
|
|
$this->assertEquals('07-01-2003', $first->getEndTimestamp('d-m-Y')); |
39
|
|
|
$this->assertEquals('08-01-2003', $last->getStartTimestamp('d-m-Y')); |
40
|
|
|
$this->assertEquals('09-01-2003', $last->getEndTimestamp('d-m-Y')); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testInitialNegativeStatementBalance() |
44
|
|
|
{ |
45
|
|
|
$this->engine->loadString(file_get_contents(__DIR__.'/sample2')); |
46
|
|
|
$statements = $this->engine->parse(); |
47
|
|
|
$this->assertEquals(-1000.12, $statements[0]->getStartPrice()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testCorrectHandlingOfVariousStatementPricing() |
51
|
|
|
{ |
52
|
|
|
$this->engine->loadString(file_get_contents(__DIR__.'/sample2')); |
53
|
|
|
$statements = $this->engine->parse(); |
54
|
|
|
$this->assertEquals(-1000.12, $statements[0]->getStartPrice()); |
55
|
|
|
$this->assertEquals(2145.23, $statements[0]->getEndPrice()); |
56
|
|
|
$this->assertEquals(-3145.35, $statements[0]->getDeltaPrice()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testHandlingOfDescriptions() { |
60
|
|
|
$this->engine->loadString(file_get_contents(__DIR__.'/sample')); |
61
|
|
|
$statements = $this->engine->parse(); |
62
|
|
|
$this->assertSame('Contante storting Overige', $statements[4]->getTransactions()[1]->getDescription()); |
63
|
|
|
$this->assertSame('INVOICE 38', $statements[14]->getTransactions()[3]->getDescription()); |
64
|
|
|
$this->assertSame('VOLGENS AFSPRAAK', $statements[15]->getTransactions()[0]->getDescription()); |
65
|
|
|
$this->assertSame('FAKTUUR 3549', $statements[15]->getTransactions()[1]->getDescription()); |
66
|
|
|
|
67
|
|
|
$this->engine->loadString(file_get_contents(__DIR__.'/sample3')); |
68
|
|
|
$statements = $this->engine->parse(); |
69
|
|
|
// enclosed |
70
|
|
|
$this->assertSame('674725433 1120000153447185 14144467636004962', $statements[0]->getTransactions()[0]->getDescription()); |
71
|
|
|
// ending |
72
|
|
|
$this->assertSame('861835-574631143', $statements[0]->getTransactions()[2]->getDescription()); |
73
|
|
|
// with slash |
74
|
|
|
$this->assertSame('/IBS.00008908/ 1001680-P796142 KINDEROPVANG', $statements[0]->getTransactions()[3]->getDescription()); |
75
|
|
|
|
76
|
|
|
$this->assertSame('Factuur 307472', $statements[1]->getTransactions()[0]->getDescription()); |
77
|
|
|
|
78
|
|
|
$this->engine->loadString(<<<PURPTEST |
79
|
|
|
:940: |
80
|
|
|
:20:940S130403 |
81
|
|
|
:25:NL50RABO0123456789 |
82
|
|
|
:28C:0 |
83
|
|
|
:60F:C130402EUR000000001147,95 |
84
|
|
|
:20:940S160503 |
85
|
|
|
:25:NL93RABO0157787990 EUR |
86
|
|
|
:28C:16085 |
87
|
|
|
:60F:C160502EUR000000146645,88 |
88
|
|
|
:61:160503D000000000015,55N102EREF |
89
|
|
|
NL34DEUT0499438906 |
90
|
|
|
:86:/EREF/02-06-2016 09:00 1230000456789011/BENM//NAME/Some Name |
91
|
|
|
d company/REMI/some descripton here that |
92
|
|
|
ends with/PURP//CD/EPAY |
93
|
|
|
:62F:C160503EUR000000146630,33 |
94
|
|
|
PURPTEST |
95
|
|
|
); |
96
|
|
|
$statements = $this->engine->parse(); |
97
|
|
|
$this->assertSame('some descripton here thatends with', $statements[1]->getTransactions()[0]->getDescription()); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.