-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathGeo6Test.php
114 lines (97 loc) · 3.2 KB
/
Geo6Test.php
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
<?php
namespace Bpost\BpostApiClient\Geo6\test;
use Bpost\BpostApiClient\Exception\BpostApiResponseException\BpostTaxipostLocatorException;
use Bpost\BpostApiClient\Geo6;
class Geo6Test extends \PHPUnit_Framework_TestCase
{
/**
* @var Geo6
*/
private $geo6;
/**
* Prepares the environment before running a test.
*/
protected function setUp()
{
parent::setUp();
$this->geo6 = new Geo6(GEO6_PARTNER, GEO6_APP_ID);
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
$this->geo6 = null;
parent::tearDown();
}
/**
* Tests Geo6->getTimeOut()
*/
public function testGetTimeOut()
{
$this->geo6->setTimeOut(5);
$this->assertSame(5, $this->geo6->getTimeOut());
}
/**
* Tests Geo6->getUserAgent()
*/
public function testGetUserAgent()
{
$this->geo6->setUserAgent('testing/1.0.0');
$this->assertSame('PHP Bpost Geo6/' . Geo6::VERSION . ' testing/1.0.0', $this->geo6->getUserAgent());
}
/**
* Tests Geo6->getNearestServicePoint()
*/
public function testGetNearestServicePoint()
{
$response = $this->geo6->getNearestServicePoint('Afrikalaan', '289', '9000');
$this->assertInternalType('array', $response);
foreach ($response as $item) {
$this->assertArrayHasKey('poi', $item);
$this->assertArrayHasKey('distance', $item);
$this->assertInstanceOf('Bpost\BpostApiClient\Geo6\Poi', $item['poi']);
}
}
/**
* Tests Geo6->getServicePointDetails()
*/
public function testGetServicePointDetails()
{
$id = '220000';
$type = '1';
$response = $this->geo6->getServicePointDetails($id, 'nl', $type);
$this->assertInstanceOf('Bpost\BpostApiClient\Geo6\Poi', $response);
$this->assertSame($response->getId(), $id);
$this->assertSame($response->getType(), $type);
try {
$this->geo6->getServicePointDetails('-1');
$this->fail('BpostTaxipostLocatorException not launched');
} catch (BpostTaxipostLocatorException $e) {
$this->assertSame('No match for id : -1 and type : 3', $e->getMessage());
} catch (\Exception $e) {
$this->fail('BpostTaxipostLocatorException not caught');
}
try {
$this->geo6->getServicePointDetails('0');
$this->fail('BpostTaxipostLocatorException not launched');
} catch (BpostTaxipostLocatorException $e) {
$this->assertSame('Id is mandatory', $e->getMessage());
} catch (\Exception $e) {
$this->fail('BpostTaxipostLocatorException not caught');
}
}
/**
* Tests Geo6->getServicePointPage()
*/
public function testGetServicePointPage()
{
$id = '220000';
$type = '1';
$response = $this->geo6->getServicePointPage($id, 'nl', $type);
$this->assertSame(
'https://taxipost.geo6.be/Locator?Id=' . $id . '&Language=nl&Type=' . $type . '&Function=page&Partner=' . GEO6_PARTNER . '&AppId=' . GEO6_APP_ID . '&Format=xml',
$response
);
}
}