Issues (41)

tests/OfxParser/OfxTest.php (4 issues)

1
<?php declare(strict_types=1);
2
3
namespace OfxParserTest;
4
5
use PHPUnit\Framework\TestCase;
6
use OfxParser\Ofx;
7
8
/**
9
 * @covers OfxParser\Ofx
10
 */
11
final class OfxTest extends TestCase
12
{
13
    /**
14
     * @var \SimpleXMLElement
15
     */
16
    protected \SimpleXMLElement $ofxData;
17
18
    public function setUp(): void
19
    {
20
        $ofxFile = dirname(__DIR__).'/fixtures/ofxdata-xml.ofx';
21
22
        if (!file_exists($ofxFile)) {
23
            self::markTestSkipped('Could not find data file, cannot test Ofx Class');
24
        }
25
        $this->ofxData = simplexml_load_string(file_get_contents($ofxFile));
26
    }
27
28
    public function testBuildsSignOn(): void
29
    {
30
        $ofx = new Ofx($this->ofxData);
31
        self::assertEquals('', $ofx->signOn->status->message);
32
        self::assertEquals('0', $ofx->signOn->status->code);
33
        self::assertEquals('INFO', $ofx->signOn->status->severity);
34
        self::assertEquals('Success', $ofx->signOn->status->codeDesc);
0 ignored issues
show
Bug Best Practice introduced by
The property codeDesc does not exist on OfxParser\Entities\Status. Since you implemented __get, consider adding a @property annotation.
Loading history...
35
36
        self::assertInstanceOf(\DateTime::class, $ofx->signOn->date);
37
        self::assertEquals('ENG', $ofx->signOn->language);
38
        self::assertEquals('MYBANK', $ofx->signOn->institute->name);
39
        self::assertEquals('01234', $ofx->signOn->institute->id);
40
    }
41
42
    public function testBuildsMultipleBankAccounts(): void
43
    {
44
        $multiOfxFile = dirname(__DIR__).'/fixtures/ofx-multiple-accounts-xml.ofx';
45
        if (!file_exists($multiOfxFile)) {
46
            self::markTestSkipped('Could not find multiple account data file, cannot fully test Multiple Bank Accounts');
47
        }
48
        $multiOfxData = simplexml_load_string(file_get_contents($multiOfxFile));
49
        $ofx = new Ofx($multiOfxData);
50
51
        self::assertCount(3, $ofx->bankAccounts);
52
        self::assertEmpty($ofx->bankAccount);
0 ignored issues
show
Deprecated Code introduced by
The property OfxParser\Ofx::$bankAccount has been deprecated: This will be removed in future versions ( Ignorable by Annotation )

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

52
        self::assertEmpty(/** @scrutinizer ignore-deprecated */ $ofx->bankAccount);

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

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

Loading history...
53
    }
54
55
    public function testBuildsBankAccount(): void
56
    {
57
        $Ofx = new Ofx($this->ofxData);
58
59
        $bankAccount = $Ofx->bankAccount;
0 ignored issues
show
Deprecated Code introduced by
The property OfxParser\Ofx::$bankAccount has been deprecated: This will be removed in future versions ( Ignorable by Annotation )

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

59
        $bankAccount = /** @scrutinizer ignore-deprecated */ $Ofx->bankAccount;

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

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

Loading history...
60
        self::assertEquals('23382938', $bankAccount->transactionUid);
61
        self::assertEquals('098-121', $bankAccount->accountNumber);
62
        self::assertEquals('987654321', $bankAccount->routingNumber);
63
        self::assertEquals('SAVINGS', $bankAccount->accountType);
64
        self::assertEquals('5250.00', $bankAccount->balance);
65
        self::assertInstanceOf('DateTime', $bankAccount->balanceDate);
66
67
        $statement = $bankAccount->statement;
68
        self::assertEquals('USD', $statement->currency);
69
        self::assertInstanceOf('DateTime', $statement->startDate);
70
        self::assertInstanceOf('DateTime', $statement->endDate);
71
72
        $transactions = $statement->transactions;
73
        self::assertCount(3, $transactions);
74
75
        $expectedTransactions = [
76
           [
77
              'type' => 'CREDIT',
78
              'typeDesc' => 'Generic credit',
79
              'amount' => '200.00',
80
              'uniqueId' => '980315001',
81
              'name' => 'DEPOSIT',
82
              'memo' => 'automatic deposit',
83
              'sic' => '',
84
              'checkNumber' => ''
85
           ],
86
           [
87
               'type' => 'CREDIT',
88
               'typeDesc' => 'Generic credit',
89
               'amount' => '150.00',
90
               'uniqueId' => '980310001',
91
               'name' => 'TRANSFER',
92
               'memo' => 'Transfer from checking',
93
               'sic' => '',
94
               'checkNumber' => ''
95
           ],
96
           [
97
               'type' => 'CHECK',
98
               'typeDesc' => 'Cheque',
99
               'amount' => '-100.00',
100
               'uniqueId' => '980309001',
101
               'name' => 'Cheque',
102
               'memo' => '',
103
               'sic' => '',
104
               'checkNumber' => '1025'
105
           ],
106
107
        ];
108
109
        foreach ($transactions as $i => $transaction) {
110
            self::assertEquals($expectedTransactions[$i]['type'], $transaction->type);
111
            self::assertEquals($expectedTransactions[$i]['typeDesc'], $transaction->typeDesc);
0 ignored issues
show
Bug Best Practice introduced by
The property typeDesc does not exist on OfxParser\Entities\Transaction. Since you implemented __get, consider adding a @property annotation.
Loading history...
112
            self::assertEquals($expectedTransactions[$i]['amount'], $transaction->amount);
113
            self::assertEquals($expectedTransactions[$i]['uniqueId'], $transaction->uniqueId);
114
            self::assertEquals($expectedTransactions[$i]['name'], $transaction->name);
115
            self::assertEquals($expectedTransactions[$i]['memo'], $transaction->memo);
116
            self::assertEquals($expectedTransactions[$i]['sic'], $transaction->sic);
117
            self::assertEquals($expectedTransactions[$i]['checkNumber'], $transaction->checkNumber);
118
            self::assertInstanceOf(\DateTime::class, $transaction->date);
119
            self::assertInstanceOf(\DateTime::class, $transaction->userInitiatedDate);
120
        }
121
    }
122
}
123