Passed
Push — master ( 6f0ea8...a91048 )
by Robin
01:54
created

TransactionTest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 158
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 74
dl 0
loc 158
rs 10
c 0
b 0
f 0
wmc 16

15 Methods

Rating   Name   Duplication   Size   Complexity  
A testPriceAssesor() 0 7 1
A testAccountNameAssesor() 0 7 1
A testAccountAssesor() 0 7 1
A testJsonSerialization() 0 21 2
A testIsCredit() 0 6 1
A testTransactionCodeAssesor() 0 7 1
A testEntryTimestampAssesor() 0 7 1
A testDebitCreditAssesorCredit() 0 7 1
A testGetValueTimestampWithFormat() 0 7 1
A testDescriptionAssesor() 0 7 1
A testIsDebit() 0 6 1
A testGetEntryTimestampWithFormat() 0 7 1
A testValueTimestampAssesor() 0 7 1
A testRelativePriceAssesor() 0 12 1
A testDebitCreditAssesorDebit() 0 7 1
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);
0 ignored issues
show
Bug introduced by
$expected of type string is incompatible with the type double expected by parameter $var of Kingsquare\Banking\Transaction::setPrice(). ( Ignorable by Annotation )

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

33
        $transaction->setPrice(/** @scrutinizer ignore-type */ $expected);
Loading history...
34
35
        $this->assertEquals($expected, $transaction->getPrice());
36
    }
37
38
    public function testRelativePriceAssesor()
39
    {
40
        $expected = '6250';
41
        $transaction = new Transaction();
42
        $transaction->setPrice($expected);
0 ignored issues
show
Bug introduced by
$expected of type string is incompatible with the type double expected by parameter $var of Kingsquare\Banking\Transaction::setPrice(). ( Ignorable by Annotation )

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

42
        $transaction->setPrice(/** @scrutinizer ignore-type */ $expected);
Loading history...
43
        $transaction->setDebitCredit('C');
44
45
        $this->assertEquals($expected, $transaction->getRelativePrice());
46
47
        $transaction->setDebitCredit('D');
48
49
        $this->assertEquals($expected * -1, $transaction->getRelativePrice());
50
    }
51
52
    public function testDebitCreditAssesorDebit()
53
    {
54
        $expected = 'D';
55
        $transaction = new Transaction();
56
        $transaction->setDebitCredit($expected);
57
58
        $this->assertEquals($expected, $transaction->getDebitCredit());
59
    }
60
61
    public function testDebitCreditAssesorCredit()
62
    {
63
        $expected = 'C';
64
        $transaction = new Transaction();
65
        $transaction->setDebitCredit($expected);
66
67
        $this->assertEquals($expected, $transaction->getDebitCredit());
68
    }
69
70
    public function testDescriptionAssesor()
71
    {
72
        $expected = 'This is a description';
73
        $transaction = new Transaction();
74
        $transaction->setDescription($expected);
75
76
        $this->assertEquals($expected, $transaction->getDescription());
77
    }
78
79
    public function testValueTimestampAssesor()
80
    {
81
        $expected = time();
82
        $transaction = new Transaction();
83
        $transaction->setValueTimestamp($expected);
84
85
        $this->assertEquals($expected, $transaction->getValueTimestamp());
86
    }
87
88
    public function testEntryTimestampAssesor()
89
    {
90
        $expected = time();
91
        $transaction = new Transaction();
92
        $transaction->setEntryTimestamp($expected);
93
94
        $this->assertEquals($expected, $transaction->getEntryTimestamp());
95
    }
96
97
    public function testTransactionCodeAssesor()
98
    {
99
        $expected = '13G';
100
        $transaction = new Transaction();
101
        $transaction->setTransactionCode($expected);
102
103
        $this->assertEquals($expected, $transaction->getTransactionCode());
104
    }
105
106
    /**
107
     * @depends testValueTimestampAssesor
108
     */
109
    public function testGetValueTimestampWithFormat()
110
    {
111
        $expected = '2012-01-01 12:00';
112
        $transaction = new Transaction();
113
        $transaction->setValueTimestamp(strtotime($expected));
114
115
        $this->assertEquals($expected, $transaction->getValueTimestamp('Y-m-d H:i'));
116
    }
117
118
    /**
119
     * @depends testEntryTimestampAssesor
120
     */
121
    public function testGetEntryTimestampWithFormat()
122
    {
123
        $expected = '2012-01-01 12:00';
124
        $transaction = new Transaction();
125
        $transaction->setEntryTimestamp(strtotime($expected));
126
127
        $this->assertEquals($expected, $transaction->getEntryTimestamp('Y-m-d H:i'));
128
    }
129
130
    public function testIsDebit()
131
    {
132
        $transaction = new Transaction();
133
        $transaction->setDebitCredit('D');
134
135
        $this->assertTrue($transaction->isDebit());
136
    }
137
138
    public function testIsCredit()
139
    {
140
        $transaction = new Transaction();
141
        $transaction->setDebitCredit('C');
142
143
        $this->assertTrue($transaction->isCredit());
144
    }
145
146
    public function testJsonSerialization()
147
    {
148
        $expected = '{"account":"123123","accountName":"Kingsquare BV","price":110,"debitcredit":"D","cancellation":false,'.
149
            '"description":"test","valueTimestamp":1231,"entryTimestamp":1234,"transactionCode":"13G"}';
150
151
        $params = [
152
            'account' => '123123',
153
            'accountName' => 'Kingsquare BV',
154
            'price' => 110.0,
155
            'debitcredit' => Transaction::DEBIT,
156
            'cancellation' => false,
157
            'description' => 'test',
158
            'valueTimestamp' => 1231,
159
            'entryTimestamp' => 1234,
160
            'transactionCode' => '13G',
161
        ];
162
        $statement = new Transaction();
163
        foreach ($params as $key => $value) {
164
            $statement->{'set'.$key}($value);
165
        }
166
        $this->assertSame($expected, json_encode($statement));
167
    }
168
}
169