Issues (19)

test/Banking/StatementTest.php (8 issues)

1
<?php
2
3
namespace Kingsquare\Banking;
4
5
/**
6
 *
7
 */
8
class StatementTest extends \PHPUnit_Framework_TestCase
9
{
10
    public function testBankAssesor()
11
    {
12
        $expected = 'ABN';
13
        $statement = new Statement();
14
        $statement->setBank($expected);
15
16
        $this->assertEquals($expected, $statement->getBank());
17
    }
18
19
    public function testAccountAssesor()
20
    {
21
        $expected = '62.90.64.393';
22
        $statement = new Statement();
23
        $statement->setAccount($expected);
24
25
        $this->assertEquals($expected, $statement->getAccount());
26
    }
27
28
    public function testTransactionsAssesor()
29
    {
30
        $expected = [
31
                new Transaction(),
32
                new Transaction(),
33
        ];
34
        $statement = new Statement();
35
        $statement->setTransactions($expected);
36
37
        $this->assertEquals($expected, $statement->getTransactions());
38
    }
39
40
    public function testStartPriceAssesor()
41
    {
42
        $expected = '6250';
43
        $statement = new Statement();
44
        $statement->setStartPrice($expected);
0 ignored issues
show
$expected of type string is incompatible with the type double expected by parameter $var of Kingsquare\Banking\Statement::setStartPrice(). ( Ignorable by Annotation )

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

44
        $statement->setStartPrice(/** @scrutinizer ignore-type */ $expected);
Loading history...
45
46
        $this->assertEquals($expected, $statement->getStartPrice());
47
    }
48
49
    public function testEndPriceAssesor()
50
    {
51
        $expected = '16250';
52
        $statement = new Statement();
53
        $statement->setEndPrice($expected);
0 ignored issues
show
$expected of type string is incompatible with the type double expected by parameter $var of Kingsquare\Banking\Statement::setEndPrice(). ( Ignorable by Annotation )

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

53
        $statement->setEndPrice(/** @scrutinizer ignore-type */ $expected);
Loading history...
54
55
        $this->assertEquals($expected, $statement->getEndPrice());
56
    }
57
58
    /**
59
     * @expectedException PHPUnit_Framework_Error_Deprecated
60
     * @expectedExceptionMessage Deprecated in favor of splitting the start and end timestamps for a statement. Please use setStartTimestamp($format) or setEndTimestamp($format) instead. setTimestamp is now setStartTimestamp
61
     */
62
    public function testDeprecatedTimestampAssesor()
63
    {
64
        $expected = time();
65
        $statement = new Statement();
66
        $statement->setTimestamp($expected);
0 ignored issues
show
Deprecated Code introduced by
The function Kingsquare\Banking\Statement::setTimestamp() has been deprecated. ( Ignorable by Annotation )

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

66
        /** @scrutinizer ignore-deprecated */ $statement->setTimestamp($expected);
Loading history...
67
68
        $this->assertEquals($expected, $statement->getTimestamp());
0 ignored issues
show
Deprecated Code introduced by
The function Kingsquare\Banking\Statement::getTimestamp() has been deprecated: This method will be removed in favor of getStartTimestamp / getEndTimestamp this is slated for removal in next major ( Ignorable by Annotation )

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

68
        $this->assertEquals($expected, /** @scrutinizer ignore-deprecated */ $statement->getTimestamp());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
69
    }
70
71
    public function testTimestampAssesor()
72
    {
73
        $time = time();
74
        $expectedStart = $time - 1440;
75
        $expectedEnd = $time;
76
        $statement = new Statement();
77
        $statement->setStartTimestamp($expectedStart);
78
        $statement->setEndTimestamp($expectedEnd);
79
80
        $this->assertEquals($expectedStart, $statement->getStartTimestamp());
81
        $this->assertEquals($expectedEnd, $statement->getEndTimestamp());
82
    }
83
84
    public function testNumberAssesor()
85
    {
86
        $expected = '2665487AAF';
87
        $statement = new Statement();
88
        $statement->setNumber($expected);
89
90
        $this->assertEquals($expected, $statement->getNumber());
91
    }
92
93
    /**
94
     * @depends testStartPriceAssesor
95
     * @depends testEndPriceAssesor
96
     */
97
    public function testDeltaPrice()
98
    {
99
        $expected = '10000';
100
        $statement = new Statement();
101
        $statement->setStartPrice('16250');
0 ignored issues
show
'16250' of type string is incompatible with the type double expected by parameter $var of Kingsquare\Banking\Statement::setStartPrice(). ( Ignorable by Annotation )

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

101
        $statement->setStartPrice(/** @scrutinizer ignore-type */ '16250');
Loading history...
102
        $statement->setEndPrice('6250');
0 ignored issues
show
'6250' of type string is incompatible with the type double expected by parameter $var of Kingsquare\Banking\Statement::setEndPrice(). ( Ignorable by Annotation )

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

102
        $statement->setEndPrice(/** @scrutinizer ignore-type */ '6250');
Loading history...
103
104
        $this->assertEquals($expected, $statement->getDeltaPrice());
105
    }
106
107
    /**
108
     * @depends testTransactionsAssesor
109
     */
110
    public function testAddTransaction()
111
    {
112
        $statement = new Statement();
113
        $statement->setTransactions([
114
                new Transaction(),
115
                new Transaction(),
116
        ]);
117
        $statement->addTransaction(new Transaction());
118
119
        $this->assertCount(3, $statement->getTransactions());
120
    }
121
122
    /**
123
     * @depends testTimestampAssesor
124
     * @expectedException PHPUnit_Framework_Error_Deprecated
125
     */
126
    public function testGetTimestampWithFormat()
127
    {
128
        $expected = '2012-01-01 12:00';
129
        $statement = new Statement();
130
        $statement->setTimestamp(strtotime($expected));
0 ignored issues
show
Deprecated Code introduced by
The function Kingsquare\Banking\Statement::setTimestamp() has been deprecated. ( Ignorable by Annotation )

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

130
        /** @scrutinizer ignore-deprecated */ $statement->setTimestamp(strtotime($expected));
Loading history...
131
132
        $this->assertEquals($expected, $statement->getTimestamp('Y-m-d H:i'));
0 ignored issues
show
Deprecated Code introduced by
The function Kingsquare\Banking\Statement::getTimestamp() has been deprecated: This method will be removed in favor of getStartTimestamp / getEndTimestamp this is slated for removal in next major ( Ignorable by Annotation )

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

132
        $this->assertEquals($expected, /** @scrutinizer ignore-deprecated */ $statement->getTimestamp('Y-m-d H:i'));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
133
    }
134
135
    public function testJsonSerialization()
136
    {
137
        $expected = '{"bank":"ABN","account":"62.90.64.393","transactions":[],'.
138
                '"startPrice":16250,"endPrice":6250,"startTimestamp":123,"endTimestamp":0,"number":"2665487AAF","currency":""}';
139
        $params = [
140
            'bank' => 'ABN',
141
            'account' => '62.90.64.393',
142
            'transactions' => [],
143
            'startPrice' => 16250,
144
            'endPrice' => 6250,
145
            'startTimestamp' => 123,
146
            'number' => '2665487AAF',
147
        ];
148
        $statement = new Statement();
149
        foreach ($params as $key => $value) {
150
            $statement->{'set'.$key}($value);
151
        }
152
        $this->assertSame($expected, json_encode($statement));
153
    }
154
155
    /**
156
     * @depends testJsonSerialization
157
     * @expectedException PHPUnit_Framework_Error_Deprecated
158
     */
159
    public function testJsonSerializationWithTransactions()
160
    {
161
        $expected = '{"bank":"ABN","account":"62.90.64.393","transactions":[{"account":"123123","accountName":'.
162
            '"Kingsquare BV","price":110,"debitcredit":"D","description":"test","valueTimestamp":1231,"entryTimestamp"'.
163
            ':1234,"transactionCode":"13G"},{"account":"123123","accountName":"Kingsquare BV","price":110,"debitcredit"'.
164
            ':"D","description":"test","valueTimestamp":1231,"entryTimestamp":1234,"transactionCode":"13G"}],'.
165
            '"startPrice":16250,"endPrice":6250,"number":"2665487AAF"}';
166
        $params = [
167
            'bank' => 'ABN',
168
            'account' => '62.90.64.393',
169
            'transactions' => [
170
                [
171
                    'account' => '123123',
172
                    'accountName' => 'Kingsquare BV',
173
                    'price' => 110.0,
174
                    'debitcredit' => Transaction::DEBIT,
175
                    'description' => 'test',
176
                    'valueTimestamp' => 1231,
177
                    'entryTimestamp' => 1234,
178
                    'transactionCode' => '13G',
179
                ],
180
                [
181
                    'account' => '123123',
182
                    'accountName' => 'Kingsquare BV',
183
                    'price' => 110.0,
184
                    'debitcredit' => Transaction::DEBIT,
185
                    'description' => 'test',
186
                    'valueTimestamp' => 1231,
187
                    'entryTimestamp' => 1234,
188
                    'transactionCode' => '13G',
189
                ],
190
            ],
191
            'startPrice' => 16250,
192
            'endPrice' => 6250,
193
            'timestamp' => 123,
194
            'number' => '2665487AAF',
195
        ];
196
        $statement = new Statement();
197
        foreach ($params as $key => $value) {
198
            $statement->{'set'.$key}($value);
199
        }
200
        $this->assertSame($expected, json_encode($statement));
201
    }
202
}
203