1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ogone\Tests\Subscription; |
4
|
|
|
|
5
|
|
|
use Ogone\Subscription\SubscriptionPaymentRequest; |
6
|
|
|
use Ogone\Subscription\SubscriptionPeriod; |
7
|
|
|
use Ogone\Tests\ShaComposer\FakeShaComposer; |
8
|
|
|
|
9
|
|
|
class SubscriptionPaymentRequestTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** @test */ |
13
|
|
|
public function AmountCanBeZero() |
14
|
|
|
{ |
15
|
|
|
$paymentRequest = $this->createSubscriptionRequest(); |
16
|
|
|
$paymentRequest->setAmount(0); |
17
|
|
|
$this->assertEquals(0, $paymentRequest->getAmount()); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @test |
22
|
|
|
* @dataProvider provideBadParameters |
23
|
|
|
* @expectedException \InvalidArgumentException |
24
|
|
|
*/ |
25
|
|
|
public function BadParametersCauseExceptions($method, $value) |
26
|
|
|
{ |
27
|
|
|
$paymentRequest = $this->createSubscriptionRequest(); |
28
|
|
|
$paymentRequest->$method($value); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @test |
33
|
|
|
* @expectedException \RuntimeException |
34
|
|
|
*/ |
35
|
|
|
public function IsInvalidIfSubscriptionParametersAreMissing() |
36
|
|
|
{ |
37
|
|
|
$paymentRequest = $this->createSubscriptionRequest(); |
38
|
|
|
$paymentRequest->setPspid('12'); |
39
|
|
|
$paymentRequest->setCurrency('EUR'); |
40
|
|
|
$paymentRequest->setAmount(0); |
41
|
|
|
$paymentRequest->setOrderId('10'); |
42
|
|
|
$paymentRequest->validate(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** @test */ |
46
|
|
|
public function RequestCanBeValid() |
47
|
|
|
{ |
48
|
|
|
$paymentRequest = $this->createSubscriptionRequest(); |
49
|
|
|
$paymentRequest->setPspid('12'); |
50
|
|
|
$paymentRequest->setCurrency('EUR'); |
51
|
|
|
$paymentRequest->setAmount(0); |
52
|
|
|
$paymentRequest->setOrderId('10'); |
53
|
|
|
$paymentRequest->setSubscriptionId('12'); |
54
|
|
|
$paymentRequest->setSubscriptionAmount(13); |
55
|
|
|
$paymentRequest->setSubscriptionComment('test'); |
56
|
|
|
$paymentRequest->setSubscriptionDescription('description'); |
57
|
|
|
$paymentRequest->setSubscriptionOrderId('13'); |
58
|
|
|
$paymentRequest->setSubscriptionPeriod($this->createSubscriptionPeriod()); |
59
|
|
|
$paymentRequest->setSubscriptionStartdate(new \DateTime()); |
60
|
|
|
$paymentRequest->setSubscriptionEnddate(new \DateTime()); |
61
|
|
|
$paymentRequest->setSubscriptionStatus(1); |
62
|
|
|
$paymentRequest->validate(); |
63
|
|
|
$this->assertTrue(true); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function provideBadParameters() |
67
|
|
|
{ |
68
|
|
|
|
69
|
|
|
return array( |
70
|
|
|
array('setAmount', 10.50), |
71
|
|
|
array('setAmount', -1), |
72
|
|
|
array('setAmount', 150000000000000000), |
73
|
|
|
array('setSubscriptionId', 'this is a little more than 50 characters, which is truly the max amount'), |
74
|
|
|
array('setSubscriptionId', '$e©ial Ch@r@cters'), |
75
|
|
|
array('setSubscriptionAmount', 10.50), |
76
|
|
|
array('setSubscriptionAmount', 0), |
77
|
|
|
array('setSubscriptionAmount', -1), |
78
|
|
|
array('setSubscriptionAmount', 150000000000000000), |
79
|
|
|
array('setSubscriptionDescription', 'this is a little more than 100 characters- which is truly the maximum amount of characters one can pass as a parameter to this particular function'), |
80
|
|
|
array('setSubscriptionDescription', 'special, characters!'), |
81
|
|
|
array('setSubscriptionOrderId', 'this is a little more than 40 characters- which is truly the max amount'), |
82
|
|
|
array('setSubscriptionOrderId', 'special, characters!'), |
83
|
|
|
array('setSubscriptionStatus', 5), |
84
|
|
|
array('setSubscriptionComment', 'this particular string is supposed to be longer than 200 characters- which will require me to type for quite a while longer than the string that needed to exceed 50 chars- which is- in fact- significantly lower than 200'), |
85
|
|
|
array('setSubscriptionComment', 'special, characters!') |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected function createSubscriptionRequest() |
90
|
|
|
{ |
91
|
|
|
return new SubscriptionPaymentRequest(new FakeShaComposer()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
protected function createSubscriptionPeriod() |
95
|
|
|
{ |
96
|
|
|
return new SubscriptionPeriod(SubscriptionPeriod::UNIT_DAILY, 12, 7); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: