PromotionsTest::testTogglePromotion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
    protected static $couponPromotionId;
12
13
    protected $promotion;
14
15
    public function setUp()
16
    {
17
        parent::setUp();
18
        $this->promotion = [
19
            'technical_name' => uniqid('promotion_', false),
20
            'name' => [
21
                'en' => 'name',
22
            ],
23
            'description' => [
24
                'en' => 'description',
25
            ],
26
            'project_id' => static::$projectId,
27
        ];
28
    }
29
30
    public function testListPromotions()
31
    {
32
        $response = static::$xsollaClient->ListPromotions();
33
        static::assertInternalType('array', $response);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
34
    }
35
36
    public function testCreatePromotion()
37
    {
38
        $response = static::$xsollaClient->CreatePromotion([
39
            'request' => $this->promotion,
40
        ]);
41
        static::assertArrayHasKey('id', $response);
42
        static::$promotionId = $response['id'];
43
    }
44
45
    /**
46
     * @depends testCreatePromotion
47
     */
48
    public function testGetPromotion()
49
    {
50
        $response = static::$xsollaClient->GetPromotion([
51
            'promotion_id' => static::$promotionId,
52
        ]);
53
        static::assertInternalType('array', $response);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
54
    }
55
56
    /**
57
     * @depends testGetPromotion
58
     */
59
    public function testUpdatePromotion()
60
    {
61
        static::$xsollaClient->UpdatePromotion([
62
            'promotion_id' => static::$promotionId,
63
            'request' => $this->promotion,
64
        ]);
65
        static::assertTrue(true);
66
    }
67
68
    /**
69
     * @depends testUpdatePromotion
70
     */
71
    public function testSetPromotionSubject()
72
    {
73
        static::$xsollaClient->SetPromotionSubject([
74
            'promotion_id' => static::$promotionId,
75
            'request' => [
76
                'purchase' => false,
77
                'items' => null,
78
                'packages' => [1],
79
            ],
80
        ]);
81
        static::assertTrue(true);
82
    }
83
84
    /**
85
     * @depends testSetPromotionSubject
86
     */
87
    public function testGetPromotionSubject()
88
    {
89
        $response = static::$xsollaClient->GetPromotionSubject([
90
            'promotion_id' => static::$promotionId,
91
        ]);
92
        static::assertInternalType('array', $response);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
93
    }
94
95
    public function testSetPromotionPaymentSystems()
96
    {
97
        static::markTestIncomplete('We haven\'t allowed payment systems for test project yet.');
98
    }
99
100
    /**
101
     * @depends testGetPromotionSubject
102
     */
103
    public function testGetPromotionPaymentSystems()
104
    {
105
        $response = static::$xsollaClient->GetPromotionPaymentSystems([
106
            'promotion_id' => static::$promotionId,
107
        ]);
108
        static::assertInternalType('array', $response);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
109
    }
110
111
    /**
112
     * @depends testGetPromotionPaymentSystems
113
     */
114
    public function testSetPromotionPeriods()
115
    {
116
        $randomFutureTimestamp = mt_rand(time() + 60, 2147483647);
117
        $datetimeStart = \DateTime::createFromFormat('U', $randomFutureTimestamp, new \DateTimeZone('UTC'));
118
        static::$xsollaClient->SetPromotionPeriods([
119
            'promotion_id' => static::$promotionId,
120
            'request' => [
121
                'periods' => [
122
                    [
123
                        'from' => $datetimeStart->format(\DateTime::ISO8601),
124
                        'to' => $datetimeStart->modify('+ 1 second')->format(\DateTime::ISO8601),
125
                    ],
126
                ],
127
            ],
128
        ]);
129
        static::assertTrue(true);
130
    }
131
132
    /**
133
     * @depends testSetPromotionPeriods
134
     */
135
    public function testGetPromotionPeriods()
136
    {
137
        $response = static::$xsollaClient->GetPromotionPeriods([
138
            'promotion_id' => static::$promotionId,
139
        ]);
140
        static::assertInternalType('array', $response);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
141
    }
142
143
    /**
144
     * @depends testGetPromotionPeriods
145
     */
146 View Code Duplication
    public function testSetPromotionRewards()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
147
    {
148
        static::$xsollaClient->SetPromotionRewards([
149
            'promotion_id' => static::$promotionId,
150
            'request' => [
151
                'purchase' => [
152
                    'discount_percent' => 10,
153
                ],
154
            ],
155
        ]);
156
        static::assertTrue(true);
157
    }
158
159
    /**
160
     * @depends testSetPromotionRewards
161
     */
162
    public function testGetPromotionRewards()
163
    {
164
        $response = static::$xsollaClient->GetPromotionRewards([
165
            'promotion_id' => static::$promotionId,
166
        ]);
167
        static::assertInternalType('array', $response);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
168
    }
169
170
    /**
171
     * @depends testGetPromotionRewards
172
     */
173
    public function testReviewPromotion()
174
    {
175
        $response = static::$xsollaClient->ReviewPromotion([
176
            'promotion_id' => static::$promotionId,
177
        ]);
178
        static::assertInternalType('array', $response);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
179
    }
180
181
    /**
182
     * @depends testReviewPromotion
183
     */
184
    public function testCreateCouponPromotion()
185
    {
186
        $response = static::$xsollaClient->CreateCouponPromotion([
187
            'request' => [
188
                'campaign_code' => uniqid('xsolla_api_test_campaign_code_', false),
189
                'project_id' => self::$projectId,
190
                'campaign_names' => ['en' => 'xsolla_api_test_campaign_code'],
191
                'redeems_count_for_user' => 1,
192
                'campaign_redeems_count_for_user' => 1,
193
                'expiration_date' => (new \DateTime('+3day'))->format(DATE_RFC3339),
194
            ],
195
        ]);
196
        static::assertInternalType('array', $response);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
197
        static::$couponPromotionId = $response['id'];
198
    }
199
200
    /**
201
     * @depends testCreateCouponPromotion
202
     */
203 View Code Duplication
    public function testGetCouponPromotions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
204
    {
205
        $response = static::$xsollaClient->ListCouponPromotions([
206
            'limit' => 20,
207
            'offset' => 0,
208
        ]);
209
        static::assertInternalType('array', $response);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
210
    }
211
212
    /**
213
     * @depends testCreateCouponPromotion
214
     */
215 View Code Duplication
    public function testUpdatePromotionCampaigns()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
216
    {
217
        static::$xsollaClient->UpdatePromotionCampaigns([
218
            'promotion_id' => static::$promotionId,
219
            'request' => [
220
                'campaigns' => [static::$couponPromotionId],
221
            ],
222
        ]);
223
        static::assertTrue(true);
224
    }
225
226
    /**
227
     * @depends testUpdatePromotionCampaigns
228
     */
229
    public function testTogglePromotion()
230
    {
231
        static::$xsollaClient->TogglePromotion([
232
            'promotion_id' => static::$promotionId,
233
        ]);
234
        static::assertTrue(true);
235
    }
236
237
    /**
238
     * @depends testUpdatePromotionCampaigns
239
     */
240
    public function testDeletePromotion()
241
    {
242
        static::$xsollaClient->DeletePromotion([
243
            'promotion_id' => static::$promotionId,
244
        ]);
245
        static::assertTrue(true);
246
    }
247
}
248