1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Xsolla\SDK\Tests\Integration\API; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @group api |
7
|
|
|
*/ |
8
|
|
|
class PromotionsTest extends AbstractAPITest |
9
|
|
|
{ |
10
|
|
|
protected static $promotionId; |
11
|
|
|
|
12
|
|
|
protected $promotion; |
13
|
|
|
|
14
|
|
|
public function setUp() |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
$this->promotion = [ |
18
|
|
|
'technical_name' => uniqid('promotion_', false), |
19
|
|
|
'name' => [ |
20
|
|
|
'en' => 'name', |
21
|
|
|
], |
22
|
|
|
'description' => [ |
23
|
|
|
'en' => 'description', |
24
|
|
|
], |
25
|
|
|
'project_id' => static::$projectId, |
26
|
|
|
]; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testListPromotions() |
30
|
|
|
{ |
31
|
|
|
$response = static::$xsollaClient->ListPromotions(); |
32
|
|
|
static::assertInternalType('array', $response); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testCreatePromotion() |
36
|
|
|
{ |
37
|
|
|
$response = static::$xsollaClient->CreatePromotion([ |
38
|
|
|
'request' => $this->promotion, |
39
|
|
|
]); |
40
|
|
|
static::assertArrayHasKey('id', $response); |
41
|
|
|
static::$promotionId = $response['id']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @depends testCreatePromotion |
46
|
|
|
*/ |
47
|
|
|
public function testGetPromotion() |
48
|
|
|
{ |
49
|
|
|
$response = static::$xsollaClient->GetPromotion([ |
50
|
|
|
'promotion_id' => static::$promotionId, |
51
|
|
|
]); |
52
|
|
|
static::assertInternalType('array', $response); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @depends testGetPromotion |
57
|
|
|
*/ |
58
|
|
|
public function testUpdatePromotion() |
59
|
|
|
{ |
60
|
|
|
$response = static::$xsollaClient->UpdatePromotion([ |
|
|
|
|
61
|
|
|
'promotion_id' => static::$promotionId, |
62
|
|
|
'request' => $this->promotion, |
63
|
|
|
]); |
64
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @depends testUpdatePromotion |
69
|
|
|
*/ |
70
|
|
|
public function testSetPromotionSubject() |
71
|
|
|
{ |
72
|
|
|
$response = static::$xsollaClient->SetPromotionSubject([ |
|
|
|
|
73
|
|
|
'promotion_id' => static::$promotionId, |
74
|
|
|
'request' => [ |
75
|
|
|
'purchase' => false, |
76
|
|
|
'items' => null, |
77
|
|
|
'packages' => [1], |
78
|
|
|
], |
79
|
|
|
]); |
80
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @depends testSetPromotionSubject |
85
|
|
|
*/ |
86
|
|
|
public function testGetPromotionSubject() |
87
|
|
|
{ |
88
|
|
|
$response = static::$xsollaClient->GetPromotionSubject([ |
89
|
|
|
'promotion_id' => static::$promotionId, |
90
|
|
|
]); |
91
|
|
|
static::assertInternalType('array', $response); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testSetPromotionPaymentSystems() |
95
|
|
|
{ |
96
|
|
|
static::markTestIncomplete('We haven\'t allowed payment systems for test project yet.'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @depends testGetPromotionSubject |
101
|
|
|
*/ |
102
|
|
|
public function testGetPromotionPaymentSystems() |
103
|
|
|
{ |
104
|
|
|
$response = static::$xsollaClient->GetPromotionPaymentSystems([ |
105
|
|
|
'promotion_id' => static::$promotionId, |
106
|
|
|
]); |
107
|
|
|
static::assertInternalType('array', $response); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @depends testGetPromotionPaymentSystems |
112
|
|
|
*/ |
113
|
|
|
public function testSetPromotionPeriods() |
114
|
|
|
{ |
115
|
|
|
$randomFutureTimestamp = mt_rand(time() + 60, 2147483647); |
116
|
|
|
$datetimeStart = \DateTime::createFromFormat('U', $randomFutureTimestamp, new \DateTimeZone('UTC')); |
117
|
|
|
$response = static::$xsollaClient->SetPromotionPeriods([ |
|
|
|
|
118
|
|
|
'promotion_id' => static::$promotionId, |
119
|
|
|
'request' => [ |
120
|
|
|
'periods' => [ |
121
|
|
|
[ |
122
|
|
|
'from' => $datetimeStart->format(\DateTime::ISO8601), |
123
|
|
|
'to' => $datetimeStart->modify('+ 1 second')->format(\DateTime::ISO8601), |
124
|
|
|
], |
125
|
|
|
], |
126
|
|
|
], |
127
|
|
|
]); |
128
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @depends testSetPromotionPeriods |
133
|
|
|
*/ |
134
|
|
|
public function testGetPromotionPeriods() |
135
|
|
|
{ |
136
|
|
|
$response = static::$xsollaClient->GetPromotionPeriods([ |
137
|
|
|
'promotion_id' => static::$promotionId, |
138
|
|
|
]); |
139
|
|
|
static::assertInternalType('array', $response); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @depends testGetPromotionPeriods |
144
|
|
|
*/ |
145
|
|
|
public function testSetPromotionRewards() |
146
|
|
|
{ |
147
|
|
|
$response = static::$xsollaClient->SetPromotionRewards([ |
|
|
|
|
148
|
|
|
'promotion_id' => static::$promotionId, |
149
|
|
|
'request' => [ |
150
|
|
|
'purchase' => [ |
151
|
|
|
'discount_percent' => 10, |
152
|
|
|
], |
153
|
|
|
], |
154
|
|
|
]); |
155
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @depends testSetPromotionRewards |
160
|
|
|
*/ |
161
|
|
|
public function testGetPromotionRewards() |
162
|
|
|
{ |
163
|
|
|
$response = static::$xsollaClient->GetPromotionRewards([ |
164
|
|
|
'promotion_id' => static::$promotionId, |
165
|
|
|
]); |
166
|
|
|
static::assertInternalType('array', $response); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @depends testGetPromotionRewards |
171
|
|
|
*/ |
172
|
|
|
public function testReviewPromotion() |
173
|
|
|
{ |
174
|
|
|
$response = static::$xsollaClient->ReviewPromotion([ |
175
|
|
|
'promotion_id' => static::$promotionId, |
176
|
|
|
]); |
177
|
|
|
static::assertInternalType('array', $response); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @depends testReviewPromotion |
182
|
|
|
*/ |
183
|
|
|
public function testTogglePromotion() |
184
|
|
|
{ |
185
|
|
|
$response = static::$xsollaClient->TogglePromotion([ |
|
|
|
|
186
|
|
|
'promotion_id' => static::$promotionId, |
187
|
|
|
]); |
188
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @depends testTogglePromotion |
193
|
|
|
*/ |
194
|
|
|
public function testDeletePromotion() |
195
|
|
|
{ |
196
|
|
|
$response = static::$xsollaClient->DeletePromotion([ |
|
|
|
|
197
|
|
|
'promotion_id' => static::$promotionId, |
198
|
|
|
]); |
199
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
202
|
|
View Code Duplication |
public function testGetCouponPromotions() |
|
|
|
|
203
|
|
|
{ |
204
|
|
|
$response = static::$xsollaClient->ListCouponPromotions([ |
205
|
|
|
'limit' => 20, |
206
|
|
|
'offset' => 0, |
207
|
|
|
]); |
208
|
|
|
static::assertInternalType('array', $response); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function testCreateCouponPromotion() |
212
|
|
|
{ |
213
|
|
|
$response = static::$xsollaClient->CreateCouponPromotion([ |
214
|
|
|
'request' => [ |
215
|
|
|
'campaign_code' => uniqid('xsolla_api_test_campaign_code_', false), |
216
|
|
|
'project_id' => self::$projectId, |
217
|
|
|
'campaign_names' => ['en' => 'xsolla_api_test_campaign_code'], |
218
|
|
|
'redeems_count_for_user' => 1, |
219
|
|
|
'campaign_redeems_count_for_user' => 1, |
220
|
|
|
'expiration_date' => (new \DateTime('+3day'))->format(DATE_RFC3339), |
221
|
|
|
], |
222
|
|
|
]); |
223
|
|
|
static::assertInternalType('array', $response); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.