Completed
Push — master ( 1b0014...e530af )
by Tobias
03:11
created

StringFormatterTest::dataProviderForTestFormat()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 95
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 95
rs 8.4117
c 0
b 0
f 0
cc 1
eloc 56
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Tests\Formatter;
14
15
use Geocoder\Formatter\StringFormatter;
16
use Geocoder\Model\Address;
17
use PHPUnit\Framework\TestCase;
18
19
/**
20
 * @author William Durand <[email protected]>
21
 */
22
class StringFormatterTest extends TestCase
23
{
24
    /**
25
     * @var StringFormatter
26
     */
27
    private $formatter;
28
29
    public function setUp()
30
    {
31
        $this->formatter = new StringFormatter();
32
    }
33
34
    /**
35
     * @dataProvider dataProviderForTestFormat
36
     */
37
    public function testFormat($data, $format, $expected)
38
    {
39
        $address = Address::createFromArray($data);
40
        $result = $this->formatter->format($address, $format);
41
42
        $this->assertTrue(is_string($result));
43
        $this->assertEquals($expected, $result);
44
    }
45
46
    public function dataProviderForTestFormat()
47
    {
48
        return [
49
            [
50
                ['streetNumber' => '10'],
51
                '%n',
52
                '10',
53
            ],
54
            [
55
                ['streetName' => 'Via San Marco'],
56
                '%S',
57
                'Via San Marco',
58
            ],
59
            [
60
                ['locality' => 'Zuerich'],
61
                '%L',
62
                'Zuerich',
63
            ],
64
            [
65
                ['postalCode' => '8001'],
66
                '%z',
67
                '8001',
68
            ],
69
            [
70
                ['adminLevels' => [['name' => 'Collin County', 'level' => 2]]],
71
                '%A2',
72
                'Collin County',
73
            ],
74
            [
75
                ['adminLevels' => [['code' => 'FC', 'level' => 2]]],
76
                '%a2',
77
                'FC',
78
            ],
79
            [
80
                ['adminLevels' => [['name' => 'Auvergne', 'level' => 1]]],
81
                '%A1',
82
                'Auvergne',
83
            ],
84
            [
85
                ['adminLevels' => [['code' => 'CA', 'level' => 1]]],
86
                '%a1',
87
                'CA',
88
            ],
89
            [
90
                ['country' => 'France'],
91
                '%C',
92
                'France',
93
            ],
94
            [
95
                ['countryCode' => 'fr'],
96
                '%c',
97
                'FR',
98
            ],
99
            [
100
                ['timezone' => 'Europe/Paris'],
101
                '%T',
102
                'Europe/Paris',
103
            ],
104
            [
105
                ['subLocality' => 'District'],
106
                '%D',
107
                'District',
108
            ],
109
            [
110
                [
111
                    'streetNumber' => '120',
112
                    'streetName' => 'Badenerstrasse',
113
                    'postalCode' => '8001',
114
                    'locality' => 'Zuerich',
115
                ],
116
                '%S %n, %z %L',
117
                'Badenerstrasse 120, 8001 Zuerich',
118
            ],
119
            [
120
                [
121
                    'streetNumber' => '120',
122
                    'streetName' => 'Badenerstrasse',
123
                    'postalCode' => '8001',
124
                    'locality' => 'Zuerich',
125
                ],
126
                '<p>%S %n, %z <a href="#%L">%L</a></p>',
127
                '<p>Badenerstrasse 120, 8001 <a href="#Zuerich">Zuerich</a></p>',
128
            ],
129
            [
130
                [
131
                    'streetNumber' => '120',
132
                    'streetName' => 'Badenerstrasse',
133
                    'postalCode' => '8001',
134
                    'locality' => 'Zuerich',
135
                ],
136
                '<p>%S %n, %z <a href="#%L">%L</a></p><p>%A2</p>',
137
                '<p>Badenerstrasse 120, 8001 <a href="#Zuerich">Zuerich</a></p><p></p>',
138
            ],
139
        ];
140
    }
141
}
142