Issues (41)

tests/OfxParser/Entities/InvestmentTest.php (3 issues)

1
<?php declare(strict_types=1);
2
3
namespace OfxParserTest\Entities;
4
5
use SimpleXMLElement;
6
use PHPUnit\Framework\TestCase;
7
use OfxParser\Entities\Investment;
8
9
/**
10
 * Need to extend the abstract Investment entity to test it.
11
 *
12
 * Defined properties, but no loadOfx method defined.
13
 */
14
class InvestmentNoLoadOfx extends Investment
15
{
16
    /**
17
     * @var string
18
     */
19
    public $public1 = 'value 100';
20
21
    /**
22
     * @var string
23
     */
24
    protected $protected1 = 'value 200';
25
26
    /**
27
     * @var string
28
     */
29
    private $private1 = 'value 300';
0 ignored issues
show
The private property $private1 is not used, and could be removed.
Loading history...
30
}
31
32
/**
33
 * Need to extend the abstract Investment entity to test it.
34
 *
35
 * This should be a "complete" investment entity
36
 */
37
class InvestmentValid extends InvestmentNoLoadOfx
38
{
39
    /**
40
     * @var string
41
     */
42
    private $private2 = 'value 310';
0 ignored issues
show
The private property $private2 is not used, and could be removed.
Loading history...
43
44
    /**
45
     * Imports the OFX data for this node.
46
     * @param SimpleXMLElement $node
47
     * @return $this
48
     */
49
    public function loadOfx(SimpleXMLElement $node)
50
    {
51
        // No-op: just need to test the exception
52
        return $this;
53
    }
54
}
55
56
/**
57
 * @covers OfxParser\Entities\Investment
58
 */
59
final class InvestmentTest extends TestCase
60
{
61
    /**
62
     * @expectedException \Exception
63
     */
64
    public function testLoadOfxException(): void
65
    {
66
        static::expectException(\Exception::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

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

66
        static::/** @scrutinizer ignore-call */ 
67
                expectException(\Exception::class);
Loading history...
67
68
        $xml = new SimpleXMLElement('<xml></xml>');
69
        $entity = new InvestmentNoLoadOfx();
70
        $entity->loadOfx($xml);
71
    }
72
73
    /**
74
     * If no exception thrown, we're good.
75
     */
76
    public function testLoadOfxValid(): void
77
    {
78
        $xml = new SimpleXMLElement('<xml></xml>');
79
        $entity = new InvestmentValid();
80
        $entity->loadOfx($xml);
81
        $this->assertTrue(true);
82
    }
83
84
    /**
85
     * If no exception thrown, we're good.
86
     */
87
    public function testGetProperties(): void
88
    {
89
        $expectedProps = [
90
            'public1',
91
            'protected1',
92
        ];
93
94
        $entity = new InvestmentValid();
95
        $actualProps = $entity->getProperties();
96
97
        $this->assertSame($expectedProps, array_keys($actualProps));
98
        $this->assertSame($expectedProps, array_values($actualProps));
99
    }
100
}
101