Completed
Push — master ( 26e69a...ab0b77 )
by Robin
03:27
created

TransactionTest::testAccountNameAssesor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Kingsquare\Banking;
4
5
/**
6
 * @author Kingsquare ([email protected])
7
 * @copyright Copyright (c) Kingsquare BV (http://www.kingsquare.nl)
8
 */
9
class TransactionTest extends \PHPUnit_Framework_TestCase
10
{
11
    public function testAccountAssesor()
12
    {
13
        $expected = '62.90.64.393';
14
        $transaction = new Transaction();
15
        $transaction->setAccount($expected);
16
17
        $this->assertEquals($expected, $transaction->getAccount());
18
    }
19
20
    public function testAccountNameAssesor()
21
    {
22
        $expected = 'Kingsquare BV';
23
        $transaction = new Transaction();
24
        $transaction->setAccountName($expected);
25
26
        $this->assertEquals($expected, $transaction->getAccountName());
27
    }
28
29
    public function testPriceAssesor()
30
    {
31
        $expected = '6250';
32
        $transaction = new Transaction();
33
        $transaction->setPrice($expected);
34
35
        $this->assertEquals($expected, $transaction->getPrice());
36
    }
37
38
    public function testDebitCreditAssesorDebit()
39
    {
40
        $expected = 'D';
41
        $transaction = new Transaction();
42
        $transaction->setDebitCredit($expected);
43
44
        $this->assertEquals($expected, $transaction->getDebitCredit());
45
    }
46
47
    public function testDebitCreditAssesorCredit()
48
    {
49
        $expected = 'C';
50
        $transaction = new Transaction();
51
        $transaction->setDebitCredit($expected);
52
53
        $this->assertEquals($expected, $transaction->getDebitCredit());
54
    }
55
56
    public function testDescriptionAssesor()
57
    {
58
        $expected = 'This is a description';
59
        $transaction = new Transaction();
60
        $transaction->setDescription($expected);
61
62
        $this->assertEquals($expected, $transaction->getDescription());
63
    }
64
65
    public function testValueTimestampAssesor()
66
    {
67
        $expected = time();
68
        $transaction = new Transaction();
69
        $transaction->setValueTimestamp($expected);
70
71
        $this->assertEquals($expected, $transaction->getValueTimestamp());
72
    }
73
74
    public function testEntryTimestampAssesor()
75
    {
76
        $expected = time();
77
        $transaction = new Transaction();
78
        $transaction->setEntryTimestamp($expected);
79
80
        $this->assertEquals($expected, $transaction->getEntryTimestamp());
81
    }
82
83
    public function testTransactionCodeAssesor()
84
    {
85
        $expected = '13G';
86
        $transaction = new Transaction();
87
        $transaction->setTransactionCode($expected);
88
89
        $this->assertEquals($expected, $transaction->getTransactionCode());
90
    }
91
92
    /**
93
     * @depends testValueTimestampAssesor
94
     */
95
    public function testGetValueTimestampWithFormat()
96
    {
97
        $expected = '2012-01-01 12:00';
98
        $transaction = new Transaction();
99
        $transaction->setValueTimestamp(strtotime($expected));
100
101
        $this->assertEquals($expected, $transaction->getValueTimestamp('Y-m-d H:i'));
102
    }
103
104
    /**
105
     * @depends testEntryTimestampAssesor
106
     */
107
    public function testGetEntryTimestampWithFormat()
108
    {
109
        $expected = '2012-01-01 12:00';
110
        $transaction = new Transaction();
111
        $transaction->setEntryTimestamp(strtotime($expected));
112
113
        $this->assertEquals($expected, $transaction->getEntryTimestamp('Y-m-d H:i'));
114
    }
115
116
    public function testIsDebit()
117
    {
118
        $transaction = new Transaction();
119
        $transaction->setDebitCredit('D');
120
121
        $this->assertTrue($transaction->isDebit());
122
    }
123
124
    public function testIsCredit()
125
    {
126
        $transaction = new Transaction();
127
        $transaction->setDebitCredit('C');
128
129
        $this->assertTrue($transaction->isCredit());
130
    }
131
132
    public function testJsonSerialization()
133
    {
134
        $expected = '{"account":"123123","accountName":"Kingsquare BV","price":110,"debitcredit":"D","cancellation":false,'.
135
            '"description":"test","valueTimestamp":1231,"entryTimestamp":1234,"transactionCode":"13G"}';
136
137
        $params = [
138
            'account' => '123123',
139
            'accountName' => 'Kingsquare BV',
140
            'price' => 110.0,
141
            'debitcredit' => Transaction::DEBIT,
142
            'cancellation' => false,
143
            'description' => 'test',
144
            'valueTimestamp' => 1231,
145
            'entryTimestamp' => 1234,
146
            'transactionCode' => '13G',
147
        ];
148
        $statement = new Transaction();
149
        foreach ($params as $key => $value) {
150
            $statement->{'set'.$key}($value);
151
        }
152
        $this->assertSame($expected, json_encode($statement));
153
    }
154
}
155