TransactionTest   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 61
c 3
b 0
f 0
dl 0
loc 124
rs 10
wmc 18

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testEntryTimestamp() 0 5 2
A testAccountName() 0 5 2
A testAccount() 0 16 2
A testParsesAllFoundStatements() 0 3 1
A testTransactionCode() 0 5 2
A testDescription() 0 15 2
A testPrice() 0 15 2
A setUp() 0 8 1
A testDebitCredit() 0 15 2
A testValueTimestamp() 0 5 2
1
<?php
2
3
namespace Kingsquare\Parser\Banking\Mt940\Engine\Triodos;
4
5
use Kingsquare\Banking\Statement;
6
use Kingsquare\Banking\Transaction;
7
use Kingsquare\Parser\Banking\Mt940\Engine\Triodos;
8
9
/**
10
 *
11
 */
12
class TransactionTest extends \PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @var Transaction[]
16
     */
17
    private $transactions = [];
18
19
    protected function setUp()
20
    {
21
        $engine = new Triodos();
22
        $engine->loadString(file_get_contents(__DIR__.'/sample'));
23
        $transactions = array_map(static function(Statement $statement) {
24
            return $statement->getTransactions();
25
        }, $engine->parse());
26
        $this->transactions = call_user_func_array('array_merge', $transactions);
27
    }
28
29
    public function testParsesAllFoundStatements()
30
    {
31
        $this->assertCount(8, $this->transactions);
32
    }
33
34
    public function testAccount()
35
    {
36
        /* @var Transaction $transaction */
37
        $known = [
38
            '555555555',
39
            '555555555',
40
            '555555555',
41
            '555555555',
42
            '888888888',
43
            '888888888',
44
            '888888888',
45
            '888888888',
46
        ];
47
48
        foreach ($this->transactions as $i => $transaction) {
49
            $this->assertSame($known[$i], $transaction->getAccount());
50
        }
51
    }
52
53
    public function testAccountName()
54
    {
55
        /* @var Transaction $transaction */
56
        foreach ($this->transactions as $i => $transaction) {
57
            $this->assertSame('TENAAMSTELLING TEGENREKENIN', $transaction->getAccountName());
58
        }
59
    }
60
61
    public function testPrice()
62
    {
63
        /* @var Transaction $transaction */
64
        $known = [
65
            10.0,
66
            250.0,
67
            150.0,
68
            40.0,
69
            8.95,
70
            25.25,
71
            150.0,
72
            56.78,
73
        ];
74
        foreach ($this->transactions as $i => $transaction) {
75
            $this->assertSame($known[$i], $transaction->getPrice());
76
        }
77
    }
78
79
    public function testDebitCredit()
80
    {
81
        /* @var Transaction $transaction */
82
        $known = [
83
            Transaction::DEBIT,
84
            Transaction::DEBIT,
85
            Transaction::CREDIT,
86
            Transaction::DEBIT,
87
            Transaction::DEBIT,
88
            Transaction::DEBIT,
89
            Transaction::CREDIT,
90
            Transaction::DEBIT,
91
        ];
92
        foreach ($this->transactions as $i => $transaction) {
93
            $this->assertSame($known[$i], $transaction->getDebitCredit());
94
        }
95
    }
96
97
    public function testDescription()
98
    {
99
        /* @var Transaction $transaction */
100
        $known = [
101
            'TENAAMSTELLING TEGENREKENING EN ADRES TEGENREKENING EN PLAATS TEGENREKENING EN EEN LANGE OMSCHRIJVING VAN DE TRANSACTIE',
102
            'TENAAMSTELLING TEGENREKENING 1111222233334444',
103
            'TENAAMSTELLING TEGENREKENING EN ADRES TEGENREKENING EN PLAATS TEGENREKENING EN EEN LANGE OMSCHRIJVING VAN DE TRANSACTIE',
104
            'TENAAMSTELLING TEGENREKENING EN ADRES TEGENREKENING EN PLAATS TEGENREKENING EN EEN LANGE OMSCHRIJVING VAN DE TRANSACTIE 1111222233334444',
105
            'TENAAMSTELLING TEGENREKENING EN ADRES TEGENREKENING EN PLAATS TEGENREKENING EN EEN LANGE OMSCHRIJVING VAN DE TRANSACTIE',
106
            'TENAAMSTELLING TEGENREKENING 1111222233334444',
107
            'TENAAMSTELLING TEGENREKENING EN ADRES TEGENREKENING EN PLAATS TEGENREKENING EN EEN LANGE OMSCHRIJVING VAN DE TRANSACTIE',
108
            'TENAAMSTELLING TEGENREKENING EN ADRES TEGENREKENING EN PLAATS TEGENREKENING EN EEN LANGE OMSCHRIJVING VAN DE TRANSACTIE 1111222233334444',
109
        ];
110
        foreach ($this->transactions as $i => $transaction) {
111
            $this->assertSame($known[$i], $transaction->getDescription());
112
        }
113
    }
114
115
    public function testValueTimestamp()
116
    {
117
        /* @var Transaction $transaction */
118
        foreach ($this->transactions as $i => $transaction) {
119
            $this->assertSame('121123', $transaction->getValueTimestamp('ymd'));
120
        }
121
    }
122
123
    public function testEntryTimestamp()
124
    {
125
        /* @var Transaction $transaction */
126
        foreach ($this->transactions as $i => $transaction) {
127
            $this->assertSame('121123', $transaction->getEntryTimestamp('ymd'));
128
        }
129
    }
130
131
    public function testTransactionCode()
132
    {
133
        /* @var Transaction $transaction */
134
        foreach ($this->transactions as $i => $transaction) {
135
            $this->assertSame('000', $transaction->getTransactionCode());
136
        }
137
    }
138
}
139