1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MOJEPANSTWO-API |
4
|
|
|
* |
5
|
|
|
* Copyright © 2017 pudelek.org.pl |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view source file |
10
|
|
|
* that is bundled with this package in the file LICENSE |
11
|
|
|
* |
12
|
|
|
* @author Marcin Pudełek <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
namespace mrcnpdlk\MojePanstwo; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
use mrcnpdlk\MojePanstwo\Model\Address\Commune; |
20
|
|
|
use mrcnpdlk\MojePanstwo\Model\Address\District; |
21
|
|
|
use mrcnpdlk\MojePanstwo\Model\Address\Nts; |
22
|
|
|
use mrcnpdlk\MojePanstwo\Model\Address\Province; |
23
|
|
|
use mrcnpdlk\MojePanstwo\Model\KrsEntity; |
24
|
|
|
use mrcnpdlk\MojePanstwo\Model\KrsEntityType; |
25
|
|
|
use mrcnpdlk\MojePanstwo\Model\SearchResponse; |
26
|
|
|
|
27
|
|
|
class ApiTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var \mrcnpdlk\MojePanstwo\Api |
31
|
|
|
*/ |
32
|
|
|
private $oApi; |
33
|
|
|
|
34
|
|
|
public function setUp() |
35
|
|
|
{ |
36
|
|
|
parent::setUp(); // TODO: Change the autogenerated stub |
37
|
|
|
$oClient = new \mrcnpdlk\MojePanstwo\Client(); |
38
|
|
|
$this->oApi = Api::create($oClient); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGetClient() |
42
|
|
|
{ |
43
|
|
|
$this->assertInstanceOf(Client::class, $this->oApi->getClient()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testGetCommune() |
47
|
|
|
{ |
48
|
|
|
$this->assertInstanceOf(Commune::class, $this->oApi->getCommune(1)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @expectedException \mrcnpdlk\MojePanstwo\Exception |
53
|
|
|
*/ |
54
|
|
|
public function testNotFound() |
55
|
|
|
{ |
56
|
|
|
$res = $this->oApi->getProvince(111111); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function testNtsConvert_one() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$oNts = new Nts('1234567891'); |
62
|
|
|
$this->assertEquals('1', $oNts->region_id); |
63
|
|
|
$this->assertEquals('23', $oNts->teryt_wojewodztwo_id); |
64
|
|
|
$this->assertEquals('45', $oNts->podregion_id); |
65
|
|
|
$this->assertEquals('67', $oNts->teryt_powiat_id); |
66
|
|
|
$this->assertEquals('89', $oNts->teryt_gmina_id); |
67
|
|
|
$this->assertEquals('1', $oNts->teryt_gmina_typ_id); |
68
|
|
|
$this->assertEquals(2367891, $oNts->teryt_terc_id); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
View Code Duplication |
public function testNtsConvert_two() |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$oNts = new Nts('11234567891'); |
74
|
|
|
$this->assertEquals('1', $oNts->region_id); |
75
|
|
|
$this->assertEquals('23', $oNts->teryt_wojewodztwo_id); |
76
|
|
|
$this->assertEquals('45', $oNts->podregion_id); |
77
|
|
|
$this->assertEquals('67', $oNts->teryt_powiat_id); |
78
|
|
|
$this->assertEquals('89', $oNts->teryt_gmina_id); |
79
|
|
|
$this->assertEquals('1', $oNts->teryt_gmina_typ_id); |
80
|
|
|
$this->assertEquals(2367891, $oNts->teryt_terc_id); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
View Code Duplication |
public function testSearchCommune() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$res = $this->oApi->searchCommune()->limit(1)->get(); |
86
|
|
|
$this->assertInstanceOf(SearchResponse::class, $res); |
87
|
|
|
$this->assertEquals(1, count($res->items)); |
88
|
|
|
$this->assertInstanceOf(Commune::class, $res->items[0]->data); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
View Code Duplication |
public function testSearchDistrict() |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
$res = $this->oApi->searchDistrict()->limit(1)->get(); |
94
|
|
|
$this->assertInstanceOf(SearchResponse::class, $res); |
95
|
|
|
$this->assertEquals(1, count($res->items)); |
96
|
|
|
$this->assertInstanceOf(District::class, $res->items[0]->data); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
View Code Duplication |
public function testSearchKrsEntity() |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
$res = $this->oApi->searchKrsEntity()->limit(1)->get(); |
102
|
|
|
$this->assertInstanceOf(SearchResponse::class, $res); |
103
|
|
|
$this->assertEquals(1, count($res->items)); |
104
|
|
|
$this->assertInstanceOf(KrsEntity::class, $res->items[0]->data); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
View Code Duplication |
public function testSearchKrsEntityType() |
|
|
|
|
108
|
|
|
{ |
109
|
|
|
$res = $this->oApi->searchKrsEntityType()->limit(1)->get(); |
110
|
|
|
$this->assertInstanceOf(SearchResponse::class, $res); |
111
|
|
|
$this->assertEquals(1, count($res->items)); |
112
|
|
|
$this->assertInstanceOf(KrsEntityType::class, $res->items[0]->data); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
View Code Duplication |
public function testSearchProvince() |
|
|
|
|
116
|
|
|
{ |
117
|
|
|
$res = $this->oApi->searchProvince()->limit(1)->get(); |
118
|
|
|
$this->assertInstanceOf(SearchResponse::class, $res); |
119
|
|
|
$this->assertEquals(1, count($res->items)); |
120
|
|
|
$this->assertInstanceOf(Province::class, $res->items[0]->data); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.