Completed
Push — master ( 281da8...5c6217 )
by
unknown
24s queued 10s
created

PromotionsTest::testCreateCouponPromotion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
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
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([
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...
61
            'promotion_id' => static::$promotionId,
62
            'request' => $this->promotion,
63
        ]);
64
        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...
65
    }
66
67
    /**
68
     * @depends testUpdatePromotion
69
     */
70
    public function testSetPromotionSubject()
71
    {
72
        $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...
73
            'promotion_id' => static::$promotionId,
74
            'request' => [
75
                'purchase' => false,
76
                'items' => null,
77
                'packages' => [1],
78
            ],
79
        ]);
80
        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...
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([
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...
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());
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...
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([
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...
148
            'promotion_id' => static::$promotionId,
149
            'request' => [
150
                'purchase' => [
151
                    'discount_percent' => 10,
152
                ],
153
            ],
154
        ]);
155
        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...
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([
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...
186
            'promotion_id' => static::$promotionId,
187
        ]);
188
        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...
189
    }
190
191
    /**
192
     * @depends testTogglePromotion
193
     */
194
    public function testDeletePromotion()
195
    {
196
        $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...
197
            'promotion_id' => static::$promotionId,
198
        ]);
199
        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...
200
    }
201
202 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...
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