1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use CorreiosAPI\Tracker; |
4
|
|
|
|
5
|
|
|
class TrackerTest extends TestCase |
6
|
|
|
{ |
7
|
|
|
protected $tracker = null; |
8
|
|
|
|
9
|
|
|
public function setup() |
10
|
|
|
{ |
11
|
|
|
$this->tracker = new Tracker('NOT', 'VALID'); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @expectedException InvalidArgumentException |
16
|
|
|
* @expectedExceptionMessageRegExp /is not a valid tracking number/ |
17
|
|
|
*/ |
18
|
|
|
public function testTrackingNumberIsInvalid1() |
19
|
|
|
{ |
20
|
|
|
$this->tracker->track('STRINGS'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @expectedException InvalidArgumentException |
25
|
|
|
* @expectedExceptionMessageRegExp /is not a valid tracking number/ |
26
|
|
|
*/ |
27
|
|
|
public function testTrackingNumberIsInvalid2() |
28
|
|
|
{ |
29
|
|
|
$this->tracker->track('123456'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @expectedException InvalidArgumentException |
34
|
|
|
* @expectedExceptionMessageRegExp /is not a valid tracking number/ |
35
|
|
|
*/ |
36
|
|
|
public function testTrackingNumberIsInvalid3() |
37
|
|
|
{ |
38
|
|
|
$this->tracker->track('0012345678900'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @expectedException InvalidArgumentException |
43
|
|
|
* @expectedExceptionMessageRegExp /is not a valid tracking number/ |
44
|
|
|
*/ |
45
|
|
|
public function testTrackingNumberIsInvalid4() |
46
|
|
|
{ |
47
|
|
|
$this->tracker->track('RRXXXXXXXXXEE'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @expectedException InvalidArgumentException |
52
|
|
|
* @expectedExceptionMessageRegExp /is not a valid tracking number/ |
53
|
|
|
*/ |
54
|
|
|
public function testTrackingNumberIsInvalid5() |
55
|
|
|
{ |
56
|
|
|
$this->tracker->track('RR1234567890E'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Bad test, API call should be mocked |
61
|
|
|
* @TODO: mock api call |
62
|
|
|
* @expectedException RuntimeException |
63
|
|
|
*/ |
64
|
|
|
public function testTrackingNumberIsValidButCredentialsAreNot() |
65
|
|
|
{ |
66
|
|
|
$this->tracker->track('RR123456789EE'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @TODO: mock api call |
71
|
|
|
*/ |
72
|
|
|
public function testApiResponseProcessingIsSuccessful() |
73
|
|
|
{ |
74
|
|
|
$goodResponse = '{}'; |
|
|
|
|
75
|
|
|
$this->markTestIncomplete('Must mock HTTP request.'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @TODO: mock api call |
80
|
|
|
* @expectedException RuntimeException |
81
|
|
|
* @expectedExceptionMessageRegExp /API call error/ |
82
|
|
|
*/ |
83
|
|
|
public function testApiResponseProcessingIsUnsuccessful() |
84
|
|
|
{ |
85
|
|
|
$badResponse = '<?xml version="1.0" encoding="iso-8859-1" ?> |
|
|
|
|
86
|
|
|
<sroxml> |
87
|
|
|
<versao>1.0</versao> |
88
|
|
|
<error>falha na autenticao do usuio</error> |
89
|
|
|
</sroxml>'; |
90
|
|
|
|
91
|
|
|
$this->markTestIncomplete('Must mock HTTP request.'); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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.