ParseTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 56
dl 0
loc 106
rs 10
c 1
b 0
f 0
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testUnStructuredMt940() 0 11 1
A testStructuredMt940() 0 6 1
A testParsesAllFoundStatements() 0 7 1
A setUp() 0 4 1
A testParseStatementBank() 0 5 1
A testCorrectHandlingOfVariousStatementPricing() 0 6 1
A testEndPrice() 0 10 1
A testStartPrice() 0 10 1
A testParseTransactionPrice() 0 7 1
A testParseTransactionDebitCredit() 0 7 1
A testSavingsAccountNumber() 0 5 1
1
<?php
2
3
namespace Kingsquare\Parser\Banking\Mt940\Engine\Knab;
4
5
use Kingsquare\Parser\Banking\Mt940\Engine\Knab;
6
7
/**
8
 *
9
 */
10
class ParseTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var Knab
14
     */
15
    private $engine;
16
17
    protected function setUp()
18
    {
19
        $this->engine = new Knab();
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('KNAB', $method->invoke($this->engine));
28
    }
29
30
    public function testParsesAllFoundStatements()
31
    {
32
        $statements = $this->engine->parse();
33
34
        $this->assertCount(1, $statements);
35
        $this->assertEquals('03-12-2015', $statements[0]->getStartTimestamp('d-m-Y'));
36
        $this->assertEquals('03-12-2015', $statements[0]->getStartTimestamp('d-m-Y'));
37
    }
38
39
    public function testCorrectHandlingOfVariousStatementPricing()
40
    {
41
        $statements = $this->engine->parse();
42
        $this->assertEquals(1000.21, $statements[0]->getStartPrice());
43
        $this->assertEquals(945.21, $statements[0]->getEndPrice());
44
        $this->assertEquals(55, $statements[0]->getDeltaPrice());
45
    }
46
47
    public function testUnStructuredMt940() {
48
        $statements = $this->engine->parse();
49
        $structuredTransaction = $statements[0]->getTransactions()[1];
50
        $this->assertEquals('NL52RABO0326203011', $structuredTransaction->getAccount());
51
        $this->assertEquals('SOME NAME', $structuredTransaction->getAccountName());
52
        $this->assertEquals('61385002542767281000000000000000000 6676341986995664 TEST PURCHAS567890', $structuredTransaction->getDescription());
53
54
        $structuredTransaction = $statements[0]->getTransactions()[3];
55
        $this->assertEquals('', $structuredTransaction->getAccount());
56
        $this->assertEquals('POS', $structuredTransaction->getAccountName());
57
        $this->assertEquals('03-12-2015 16:04 PAS: 1122', $structuredTransaction->getDescription());
58
    }
59
60
    public function testStructuredMt940() {
61
        $statements = $this->engine->parse();
62
        $structuredTransaction = $statements[0]->getTransactions()[4];
63
        $this->assertEquals('437015300', $structuredTransaction->getAccount());
64
        $this->assertEquals('ACHMEA SCHADEVERZEKERINGEN N.V.', $structuredTransaction->getAccountName());
65
        $this->assertEquals('EERSTE MAAND, MAART VERZEKERING 5002100023 310160', $structuredTransaction->getDescription());
66
    }
67
68
69
    public function testStartPrice() {
70
        $this->engine->loadString(file_get_contents(__DIR__.'/sample'));
71
        $statements = $this->engine->parse();
72
        $start_price_m = $statements[0]->getStartPrice();
73
        $this->assertSame(1000.21 , $start_price_m);
74
75
        $this->engine->loadString(file_get_contents(__DIR__.'/sample2'));
76
        $statements = $this->engine->parse();
77
        $start_price_f = $statements[0]->getStartPrice();
78
        $this->assertSame(12490.07 , $start_price_f);
79
    }
80
81
    public function testEndPrice() {
82
        $this->engine->loadString(file_get_contents(__DIR__.'/sample'));
83
        $statements = $this->engine->parse();
84
        $price_m = $statements[0]->getEndPrice();
85
        $this->assertSame(945.21 , $price_m);
86
87
        $this->engine->loadString(file_get_contents(__DIR__.'/sample2'));
88
        $statements = $this->engine->parse();
89
        $price_f = $statements[0]->getEndPrice();
90
        $this->assertSame(13057.49 , $price_f);
91
    }
92
    
93
    public function testParseTransactionDebitCredit()
94
    {
95
        $statements = $this->engine->parse();
96
        $transactions = reset($statements)->getTransactions();
97
        $firstTransaction = reset($transactions);
98
99
        $this->assertEquals('D', $firstTransaction->getDebitCredit());
100
    }
101
    
102
    public function testParseTransactionPrice()
103
    {
104
        $statements = $this->engine->parse();
105
        $transactions = reset($statements)->getTransactions();
106
        $firstTransaction = reset($transactions);
107
108
        $this->assertEquals(15, $firstTransaction->getPrice());
109
    }
110
    
111
    public function testSavingsAccountNumber()
112
    {
113
        $this->engine->loadString(file_get_contents(__DIR__ . '/sample3'));
114
        $statements = $this->engine->parse();
115
        $this->assertEquals('P53851317', $statements[0]->getTransactions()[0]->getAccount());
116
    }
117
}
118