testFaultyNumberProperties()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests\Bpost\Order;
4
5
use Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress;
6
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException;
7
use DOMDocument;
8
use PHPUnit_Framework_TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class ParcelsDepotAddressTest extends PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * Create a generic DOM Document
14
     *
15
     * @return DOMDocument
16
     */
17
    private static function createDomDocument()
18
    {
19
        $document = new DOMDocument('1.0', 'utf-8');
20
        $document->preserveWhiteSpace = false;
21
        $document->formatOutput = true;
22
23
        return $document;
24
    }
25
26
    /**
27
     * Tests Address->toXML
28
     */
29
    public function testToXML()
30
    {
31
        $data = array(
32
            'streetName' => 'Afrikalaan',
33
            'number' => '2890',
34
            'box' => '3',
35
            'postalCode' => '9000',
36
            'locality' => 'Gent',
37
            'countryCode' => 'BE',
38
        );
39
40
        $expectedDocument = self::createDomDocument();
41
        $address = $expectedDocument->createElement('parcelsDepotAddress');
42
        foreach ($data as $key => $value) {
43
            $address->appendChild(
44
                $expectedDocument->createElement($key, $value)
45
            );
46
        }
47
        $expectedDocument->appendChild($address);
48
49
        $actualDocument = self::createDomDocument();
50
        $address = new ParcelsDepotAddress(
51
            $data['streetName'],
52
            $data['number'],
53
            $data['box'],
54
            $data['postalCode'],
55
            $data['locality'],
56
            $data['countryCode']
57
        );
58
        $actualDocument->appendChild(
59
            $address->toXML($actualDocument, null)
60
        );
61
62
        $this->assertEquals($expectedDocument, $actualDocument);
63
    }
64
65
    /**
66
     * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException
67
     *
68
     * @throws BpostInvalidLengthException
69
     */
70
    public function testFaultyProperties()
71
    {
72
        $address = new ParcelsDepotAddress();
73
        $address->setBox(str_repeat('a', 9));
74
    }
75
76
    /**
77
     * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException
78
     *
79
     * @throws BpostInvalidLengthException
80
     */
81
    public function testFaultyCountryCodeProperties()
82
    {
83
        $address = new ParcelsDepotAddress();
84
        $address->setCountryCode(str_repeat('a', 3));
85
    }
86
87
    /**
88
     * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException
89
     *
90
     * @throws BpostInvalidLengthException
91
     */
92
    public function testFaultyLocalityProperties()
93
    {
94
        $address = new ParcelsDepotAddress();
95
        $address->setLocality(str_repeat('a', 41));
96
    }
97
98
    /**
99
     * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException
100
     *
101
     * @throws BpostInvalidLengthException
102
     */
103
    public function testFaultyNumberProperties()
104
    {
105
        $address = new ParcelsDepotAddress();
106
        $address->setNumber(str_repeat('a', 9));
107
    }
108
109
    /**
110
     * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException
111
     *
112
     * @throws BpostInvalidLengthException
113
     */
114
    public function testFaultyPostalCodeProperties()
115
    {
116
        $address = new ParcelsDepotAddress();
117
        $address->setPostalCode(str_repeat('a', 41));
118
    }
119
120
    /**
121
     * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException
122
     *
123
     * @throws BpostInvalidLengthException
124
     */
125
    public function testFaultyStreetNameProperties()
126
    {
127
        $address = new ParcelsDepotAddress();
128
        $address->setStreetName(str_repeat('a', 41));
129
    }
130
}
131