Completed
Push — master ( 7fb034...fe2c36 )
by
unknown
9s
created

PromotionsTest::testUpdatePromotionCampaigns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
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);
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);
54
    }
55
56
    /**
57
     * @depends testGetPromotion
58
     */
59
    public function testUpdatePromotion()
60
    {
61
        $response = static::$xsollaClient->UpdatePromotion([
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $response is correct as static::$xsollaClient->U...' => $this->promotion)) (which targets Xsolla\SDK\API\XsollaClient::UpdatePromotion()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

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.

Loading history...
62
            'promotion_id' => static::$promotionId,
63
            'request' => $this->promotion,
64
        ]);
65
        static::assertSame(204, $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method getStatusCode cannot be called on $response (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
66
    }
67
68
    /**
69
     * @depends testUpdatePromotion
70
     */
71
    public function testSetPromotionSubject()
72
    {
73
        $response = static::$xsollaClient->SetPromotionSubject([
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $response is correct as static::$xsollaClient->S...ackages' => array(1)))) (which targets Xsolla\SDK\API\XsollaClient::SetPromotionSubject()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

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.

Loading history...
74
            'promotion_id' => static::$promotionId,
75
            'request' => [
76
                'purchase' => false,
77
                'items' => null,
78
                'packages' => [1],
79
            ],
80
        ]);
81
        static::assertSame(204, $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method getStatusCode cannot be called on $response (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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);
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);
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
        $response = static::$xsollaClient->SetPromotionPeriods([
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $response is correct as static::$xsollaClient->S...DateTime::ISO8601)))))) (which targets Xsolla\SDK\API\XsollaClient::SetPromotionPeriods()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

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.

Loading history...
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::assertSame(204, $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method getStatusCode cannot be called on $response (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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);
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
        $response = static::$xsollaClient->SetPromotionRewards([
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $response is correct as static::$xsollaClient->S...ount_percent' => 10)))) (which targets Xsolla\SDK\API\XsollaClient::SetPromotionRewards()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

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.

Loading history...
149
            'promotion_id' => static::$promotionId,
150
            'request' => [
151
                'purchase' => [
152
                    'discount_percent' => 10,
153
                ],
154
            ],
155
        ]);
156
        static::assertSame(204, $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method getStatusCode cannot be called on $response (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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);
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);
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);
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);
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
        $response = static::$xsollaClient->UpdatePromotionCampaigns([
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $response is correct as static::$xsollaClient->U...:$couponPromotionId)))) (which targets Xsolla\SDK\API\XsollaCli...atePromotionCampaigns()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

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.

Loading history...
218
            'promotion_id' => static::$promotionId,
219
            'request' => [
220
                'campaigns' => [static::$couponPromotionId],
221
            ],
222
        ]);
223
        static::assertSame(204, $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method getStatusCode cannot be called on $response (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
224
    }
225
226
    /**
227
     * @depends testUpdatePromotionCampaigns
228
     */
229
    public function testTogglePromotion()
230
    {
231
        $response = static::$xsollaClient->TogglePromotion([
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $response is correct as static::$xsollaClient->T... static::$promotionId)) (which targets Xsolla\SDK\API\XsollaClient::TogglePromotion()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

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.

Loading history...
232
            'promotion_id' => static::$promotionId,
233
        ]);
234
        static::assertSame(204, $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method getStatusCode cannot be called on $response (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
235
    }
236
237
    /**
238
     * @depends testUpdatePromotionCampaigns
239
     */
240
    public function testDeletePromotion()
241
    {
242
        $response = static::$xsollaClient->DeletePromotion([
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $response is correct as static::$xsollaClient->D... static::$promotionId)) (which targets Xsolla\SDK\API\XsollaClient::DeletePromotion()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

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.

Loading history...
243
            'promotion_id' => static::$promotionId,
244
        ]);
245
        static::assertSame(204, $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method getStatusCode cannot be called on $response (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
246
    }
247
}
248