ParseTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 41
dl 0
loc 84
rs 10
c 1
b 0
f 1
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseStatementBank() 0 5 1
A setUp() 0 4 1
A testParseTransactionEntryTimestamp() 0 23 1
A testParsesAllFoundStatements() 0 21 1
A testParseTransactionDebitCredit() 0 7 1
A testParseTransactionPrice() 0 7 1
1
<?php
2
3
namespace Kingsquare\Parser\Banking\Mt940\Engine\Kbs;
4
5
use Kingsquare\Parser\Banking\Mt940\Engine\Kbs;
6
7
class ParseTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var Kbs
11
     */
12
    private $engine;
13
14
    protected function setUp()
15
    {
16
        $this->engine = new Kbs();
17
        $this->engine->loadString(file_get_contents(__DIR__ . '/sample'));
18
    }
19
20
    public function testParseStatementBank()
21
    {
22
        $method = new \ReflectionMethod($this->engine, 'parseStatementBank');
23
        $method->setAccessible(true);
24
        $this->assertEquals('KBS', $method->invoke($this->engine));
25
    }
26
27
    public function testParsesAllFoundStatements()
28
    {
29
        $statements = $this->engine->parse();
30
31
        $this->assertCount(1, $statements);
32
        $first = $statements[0];
33
34
        $this->assertEquals('01-12-2020', $first->getStartTimestamp('d-m-Y'));
35
        $this->assertEquals('01-12-2020', $first->getEndTimestamp('d-m-Y'));
36
        $this->assertEquals(-1870, $first->getDeltaPrice());
37
38
        $this->engine->loadString(file_get_contents(__DIR__.'/sample2'));
39
        
40
        $statements = $this->engine->parse();
41
42
        $this->assertCount(1, $statements);
43
        $first = $statements[0];
44
45
        $this->assertEquals('09-10-2020', $first->getStartTimestamp('d-m-Y'));
46
        $this->assertEquals('09-10-2020', $first->getEndTimestamp('d-m-Y'));
47
        $this->assertEquals(-22755, $first->getDeltaPrice());
48
    }
49
50
    public function testParseTransactionEntryTimestamp()
51
    {
52
        $statements = $this->engine->parse();
53
        $transactions = reset($statements)->getTransactions();
54
        // the first has no entryTimestamp
55
        $firstTransaction = reset($transactions);
56
        $this->assertEquals('01-12-2020', $firstTransaction->getEntryTimestamp('d-m-Y'));
57
58
        // the last does have an entryTimestamp (custom edited)
59
        $lastTransaction = end($transactions);
60
        $this->assertEquals('01-12-2020', $lastTransaction->getEntryTimestamp('d-m-Y'));
61
        
62
        $this->engine->loadString(file_get_contents(__DIR__.'/sample2'));
63
        
64
        $statements = $this->engine->parse();
65
        $transactions = reset($statements)->getTransactions();
66
        // the first has no entryTimestamp
67
        $firstTransaction = reset($transactions);
68
        $this->assertEquals('09-10-2020', $firstTransaction->getEntryTimestamp('d-m-Y'));
69
70
        // the last does have an entryTimestamp (custom edited)
71
        $lastTransaction = end($transactions);
72
        $this->assertEquals('09-10-2020', $lastTransaction->getEntryTimestamp('d-m-Y'));
73
    }
74
75
    public function testParseTransactionDebitCredit()
76
    {
77
        $statements = $this->engine->parse();
78
        $transactions = reset($statements)->getTransactions();
79
        $firstTransaction = reset($transactions);
80
81
        $this->assertEquals('D', $firstTransaction->getDebitCredit());
82
    }
83
    
84
    public function testParseTransactionPrice()
85
    {
86
        $statements = $this->engine->parse();
87
        $transactions = reset($statements)->getTransactions();
88
        $firstTransaction = reset($transactions);
89
90
        $this->assertEquals(80, $firstTransaction->getPrice());
91
    }
92
}
93