Passed
Pull Request — master (#84)
by
unknown
01:23
created

ParseTest::testParseTransactionDebitCredit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Kingsquare\Parser\Banking\Mt940\Engine\Abn;
4
5
use Kingsquare\Parser\Banking\Mt940\Engine\Abn;
6
7
/**
8
 *
9
 */
10
class ParseTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var Abn
14
     */
15
    private $engine;
16
17
    protected function setUp()
18
    {
19
        $this->engine = new Abn();
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('ABN', $method->invoke($this->engine));
28
    }
29
30
    public function testParsesAllFoundStatements()
31
    {
32
        $statements = $this->engine->parse();
33
34
        $this->assertCount(4, $statements);
35
        $first = $statements[0];
36
        $last = end($statements);
37
38
        $this->assertEquals('23-06-2009', $first->getStartTimestamp('d-m-Y'));
39
        $this->assertEquals('24-06-2009', $first->getEndTimestamp('d-m-Y'));
40
        $this->assertEquals(210.5, $first->getDeltaPrice());
41
42
        $this->assertEquals('23-06-2009', $last->getStartTimestamp('d-m-Y'));
43
        $this->assertEquals('24-06-2009', $last->getEndTimestamp('d-m-Y'));
44
    }
45
46
    public function testHandleEntryYearRollover()
47
    {
48
        $this->engine->loadString(file_get_contents(__DIR__.'/sample2'));
49
        $statements = $this->engine->parse();
50
51
        $this->assertCount(1, $statements);
52
        list($sameday, $nextDay, $nextMonth, $nextYear) = $statements[0]->getTransactions();
53
54
        $this->assertEquals('01-01-2009', $sameday->getValueTimestamp('d-m-Y'));
55
        $this->assertEquals('01-01-2009', $sameday->getEntryTimestamp('d-m-Y'));
56
57
        $this->assertEquals('01-01-2009', $nextDay->getValueTimestamp('d-m-Y'));
58
        $this->assertEquals('02-01-2009', $nextDay->getEntryTimestamp('d-m-Y'));
59
60
        $this->assertEquals('01-01-2009', $nextMonth->getValueTimestamp('d-m-Y'));
61
        $this->assertEquals('01-02-2009', $nextMonth->getEntryTimestamp('d-m-Y'));
62
63
        $this->assertEquals('31-12-2009', $nextYear->getValueTimestamp('d-m-Y'));
64
        $this->assertEquals('01-01-2010', $nextYear->getEntryTimestamp('d-m-Y'));
65
    }
66
67
    public function testIssue48()
68
    {
69
        $this->engine->loadString(file_get_contents(__DIR__.'/issue48'));
70
        $statements = $this->engine->parse();
71
72
        $this->assertCount(1, $statements);
73
        $transactions = $statements[0]->getTransactions();
74
75
        $this->assertEquals('15-12-2016', $transactions[0]->getValueTimestamp('d-m-Y'));
76
        $this->assertEquals('15-12-2016', $transactions[0]->getEntryTimestamp('d-m-Y'));
77
78
        $this->assertEquals('15-12-2016', $transactions[1]->getValueTimestamp('d-m-Y'));
79
        $this->assertEquals('15-12-2016', $transactions[1]->getEntryTimestamp('d-m-Y'));
80
    }
81
    
82
    public function testParseTransactionDebitCredit()
83
    {
84
        $statements = $this->engine->parse();
85
        $transactions = reset($statements)->getTransactions();
86
        $firstTransaction = reset($transactions);
87
88
        $this->assertEquals('D', $firstTransaction->getDebitCredit());
89
    }
90
    
91
    public function testParseTransactionPrice()
92
    {
93
        $statements = $this->engine->parse();
94
        $transactions = reset($statements)->getTransactions();
95
        $firstTransaction = reset($transactions);
96
97
        $this->assertEquals(7.5, $firstTransaction->getPrice());
98
    }
99
}
100