-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGermanAddressValidationTest.php
More file actions
127 lines (111 loc) · 3.18 KB
/
GermanAddressValidationTest.php
File metadata and controls
127 lines (111 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* Author: ojooss
* Copyright 2019
*/
require_once __DIR__.'/GermanAddressValidation.php';
use PHPUnit\Framework\TestCase;
final class GermanAddressValidationTest extends TestCase
{
/**
* @var GermanAddressValidation
*/
protected GermanAddressValidation $testObject;
public function setUp(): void
{
$this->testObject = new GermanAddressValidation();
}
/**
* @return array
*/
public static function providerSearchCityByPostCode(): array
{
return array(
array('80636', 'München'),
array('30179', 'Hannover'),
array('09456', 'Annaberg-Buchholz'),
array('00636', 'invalid'),
);
}
/**
* @param string $postCode
* @param string $expected
*
* @throws Exception
* @dataProvider providerSearchCityByPostCode
*/
public function testSearchCityByPostCode(string $postCode, string $expected): void
{
$matches = $this->testObject->searchCityByPostCode($postCode);
$city = (count($matches) > 0)?$matches[0]->city:'invalid';
$this->assertEquals( $expected, $city);
}
/**
* @return array
*/
public static function providerValidatePostCode(): array
{
return array(
array('80636', true),
array('00636', false),
);
}
/**
* @param string $postCode
* @param bool $expected
*
* @throws Exception
* @dataProvider providerValidatePostCode
*/
public function testValidatePostCode(string $postCode, bool $expected): void
{
$this->assertEquals( $expected, $this->testObject->validatePostCode($postCode));
}
/**
* @return array
*/
public static function providerSearchPostCodeByCityStreet(): array
{
return array(
array('München', 'Erika-Mann-Straße 33', '80636'),
array('München', 'Konrad-Adenauer-Straße 17', 'invalid'),
);
}
/**
* @param string $city
* @param string $street
* @param string $expected
*
* @throws Exception
* @dataProvider providerSearchPostCodeByCityStreet
*/
public function testSearchPostCodeByCityStreet(string $city, string $street, string $expected): void
{
$matches = $this->testObject->searchPostCodeByCityStreet($city, $street);
$postCode = (count($matches) > 0)?$matches[0]->plz:'invalid';
$this->assertEquals( $expected, $postCode);
}
/**
* @return array
*/
public static function providerValidateAddress(): array
{
return array(
array('München', 'Erika-Mann-Straße 33', '80636', true),
array('München', 'Erika-Mann-Straße 33', '80686', false),
);
}
/**
* @param string $city
* @param string $street
* @param string $postCode
* @param bool $expected
*
* @throws Exception
* @dataProvider providerValidateAddress
*/
public function testValidateAddress(string $city, string $street, string $postCode, bool $expected): void
{
$this->assertEquals( $expected, $this->testObject->validateAddress($city, $street, $postCode));
}
}