ParseTest::testParsesAllFoundStatements()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Kingsquare\Parser\Banking\Mt940\Engine\Hsbc;
4
5
use Kingsquare\Parser\Banking\Mt940\Engine\Hsbc;
6
7
/**
8
 *
9
 */
10
class ParseTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var Hsbc
14
     */
15
    private $engine;
16
17
    protected function setUp()
18
    {
19
        $this->engine = new Hsbc();
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('HSBC', $method->invoke($this->engine));
28
    }
29
30
    public function testParsesAllFoundStatements()
31
    {
32
        $statements = $this->engine->parse();
33
34
        $this->assertCount(1, $statements);
35
        $first = $statements[0];
36
        $last = end($statements);
37
        $this->assertEquals('2012-03-29', $first->getStartTimestamp('Y-m-d'));
38
        $this->assertEquals('2012-03-29', $first->getEndTimestamp('Y-m-d'));
39
        $this->assertEquals('2012-03-29', $last->getStartTimestamp('Y-m-d'));
40
        $this->assertEquals('2012-03-29', $last->getEndTimestamp('Y-m-d'));
41
    }
42
43
    public function testStatementBalance()
44
    {
45
        $this->engine->loadString(file_get_contents(__DIR__ . '/sample'));
46
        $statements = $this->engine->parse();
47
        $this->assertEquals(0.00, $statements[0]->getStartPrice());
48
        $this->assertEquals(0.00, $statements[0]->getEndPrice());
49
        $this->assertEquals(0.00, $statements[0]->getDeltaPrice());
50
        $this->assertEquals('HKD', $statements[0]->getCurrency());
51
        $this->assertEquals('D', $statements[0]->getTransactions()[0]->getDebitCredit());
52
        $this->assertEquals(20000, $statements[0]->getTransactions()[0]->getPrice());
53
        $this->assertEquals('1004688128', $statements[0]->getTransactions()[0]->getAccount());
54
        $this->assertEquals('//6128522200250001', $statements[0]->getTransactions()[0]->getAccountName());
55
    }
56
57
    public function testHandlingOfDescriptions()
58
    {
59
        $this->engine->loadString(file_get_contents(__DIR__ . '/sample'));
60
        $statements = $this->engine->parse();
61
        $first = $statements[0];
62
        $expected = '/OCMT/USD2853,12/PAYMENT OF INVOICES 204011665 20401 1687/OGB/WXXXXX BANKING CORPORATION /VA/123456XXXXXXBENEFICIARY INFO/OSDR/HSBCHKHH-';
63
        $this->assertSame($expected, $first->getTransactions()[0]->getDescription());
64
65
        $expected = '123456XXXXXX';
66
        $this->assertSame($expected, $first->getTransactions()[0]->getVirtualAccount());
0 ignored issues
show
introduced by
The method getVirtualAccount() does not exist on Kingsquare\Banking\Transaction. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        $this->assertSame($expected, $first->getTransactions()[0]->/** @scrutinizer ignore-call */ getVirtualAccount());
Loading history...
67
68
        $this->engine->loadString(<<<EOF
69
:20:AIU0006362100017
70
:25:808XXXXXX292
71
:28C:00001/00001
72
:60F:C120329HKD0,00
73
:61:1203290329DD20000,00NTRF1004688128      //6128522200250001
74
:86:/A
75
/B
76
/C
77
:62F:C120329HKD0,00
78
:64:C120329HKD0,00
79
:86:/D
80
-
81
EOF
82
        );
83
        $statements = $this->engine->parse();
84
        $this->assertSame('/A/B/C/D-', $statements[0]->getTransactions()[0]->getDescription());
85
    }
86
}
87