1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* @author Nicolas Clavaud <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Ogone\Tests\DirectLink; |
7
|
|
|
|
8
|
|
|
use Ogone\DirectLink\DirectLinkMaintenanceResponse; |
9
|
|
|
|
10
|
|
View Code Duplication |
class DirectLinkMaintenanceResponseTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @test |
15
|
|
|
* @expectedException InvalidArgumentException |
16
|
|
|
*/ |
17
|
|
|
public function CantExistWithoutXmlFile() |
18
|
|
|
{ |
19
|
|
|
$maintenanceResponse = new DirectLinkMaintenanceResponse(''); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** @test */ |
23
|
|
|
public function ParametersCanBeRetrieved() |
24
|
|
|
{ |
25
|
|
|
$xml = $this->provideXML(); |
26
|
|
|
|
27
|
|
|
$maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
28
|
|
|
$this->assertEquals('5', $maintenanceResponse->getParam('orderid')); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @test |
33
|
|
|
* @expectedException InvalidArgumentException |
34
|
|
|
*/ |
35
|
|
|
public function RequestIsFilteredFromNonOgoneParameters() |
36
|
|
|
{ |
37
|
|
|
$xml = $this->provideXML(); |
38
|
|
|
|
39
|
|
|
$maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
40
|
|
|
$maintenanceResponse->getParam('unknown_param'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
* @expectedException InvalidArgumentException |
46
|
|
|
*/ |
47
|
|
|
public function ChecksInvalidXml() |
48
|
|
|
{ |
49
|
|
|
$xml = $this->provideInvalidXML(); |
50
|
|
|
|
51
|
|
|
$maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** @test */ |
55
|
|
|
public function ChecksStatus() |
56
|
|
|
{ |
57
|
|
|
$xml = $this->provideXML(); |
58
|
|
|
|
59
|
|
|
$maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
60
|
|
|
$this->assertTrue($maintenanceResponse->isSuccessful()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** @test */ |
64
|
|
|
public function AmountIsConvertedToCent() |
65
|
|
|
{ |
66
|
|
|
$xml = $this->provideXML(); |
67
|
|
|
|
68
|
|
|
$maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
69
|
|
|
$this->assertEquals(100, $maintenanceResponse->getParam('amount')); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function provideFloats() |
73
|
|
|
{ |
74
|
|
|
return array( |
75
|
|
|
array('17.89', 1789), |
76
|
|
|
array('65.35', 6535), |
77
|
|
|
array('12.99', 1299), |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @test |
83
|
|
|
* @dataProvider provideFloats |
84
|
|
|
*/ |
85
|
|
|
public function CorrectlyConvertsFloatAmountsToInteger($string, $integer) |
86
|
|
|
{ |
87
|
|
|
$xml = $this->provideXML($string); |
88
|
|
|
|
89
|
|
|
$maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
90
|
|
|
$this->assertEquals($integer, $maintenanceResponse->getParam('amount')); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Helper method to setup an xml-string |
95
|
|
|
*/ |
96
|
|
|
private function provideXML($amount = null) |
97
|
|
|
{ |
98
|
|
|
|
99
|
|
|
$xml = '<?xml version="1.0"?> |
100
|
|
|
<ncresponse |
101
|
|
|
orderID="5" |
102
|
|
|
PAYID="33146134" |
103
|
|
|
NCERROR="0" |
104
|
|
|
NCERRORPLUS="!" |
105
|
|
|
ACCEPTANCE="" |
106
|
|
|
STATUS="91" |
107
|
|
|
AMOUNT="'.(($amount) ? $amount : '1').'" |
108
|
|
|
CURRENCY="GBP"> |
109
|
|
|
</ncresponse>'; |
110
|
|
|
|
111
|
|
|
return $xml; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Helper method to setup an invalid xml-string |
116
|
|
|
*/ |
117
|
|
|
private function provideInvalidXML() |
118
|
|
|
{ |
119
|
|
|
$xml = '<?xml version="1.0"?> |
120
|
|
|
<ncresponse |
121
|
|
|
</ncresponse>'; |
122
|
|
|
|
123
|
|
|
return $xml; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.