Completed
Pull Request — master (#37)
by Vitaliy
06:37 queued 03:31
created

WalletTest::testAddVirtualItemToWalletUser()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 40
rs 8.8571
cc 1
eloc 26
nc 1
nop 0
1
<?php
2
3
namespace Xsolla\SDK\Tests\Integration\API;
4
5
/**
6
 * @group api
7
 */
8
class WalletTest extends AbstractAPITest
9
{
10
    protected static $virtualItemId;
11
    protected static $virtualItemSku;
12
13
    public function testCreateWalletUser()
14
    {
15
        static::markTestIncomplete('Delete user API method not implemented yet. We should not create new users infinitely.');
16
    }
17
18 View Code Duplication
    public function testGetWalletUser()
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...
19
    {
20
        $response = static::$xsollaClient->GetWalletUser(array(
21
            'project_id' => static::$projectId,
22
            'user_id' => static::$userId,
23
        ));
24
        static::assertInternalType('array', $response);
25
    }
26
27
    public function testUpdateWalletUser()
28
    {
29
        static::$xsollaClient->UpdateWalletUser(array(
30
            'project_id' => static::$projectId,
31
            'user_id' => static::$userId,
32
            'request' => array(
33
                'enabled' => true,
34
            ),
35
        ));
36
    }
37
38
    public function testListWalletUsers()
39
    {
40
        $response = static::$xsollaClient->ListWalletUsers(array(
41
            'project_id' => static::$projectId,
42
            'limit' => 1,
43
            'offset' => 0,
44
        ));
45
        static::assertInternalType('array', $response);
46
    }
47
48 View Code Duplication
    public function testListWalletUserOperations()
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...
49
    {
50
        $response = static::$xsollaClient->ListWalletUserOperations(array(
51
            'project_id' => static::$projectId,
52
            'user_id' => static::$userId,
53
            'datetime_from' => '2015-01-01T00:00:00 UTC',
54
            'datetime_to' => '2016-01-01T00:00:00 UTC',
55
        ));
56
        static::assertInternalType('array', $response);
57
    }
58
59 View Code Duplication
    public function testRechargeWalletUserBalance()
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...
60
    {
61
        $response = static::$xsollaClient->RechargeWalletUserBalance(array(
62
            'project_id' => static::$projectId,
63
            'user_id' => static::$userId,
64
            'request' => array(
65
                'amount' => 10,
66
                'comment' => 'Comment',
67
            ),
68
        ));
69
        static::assertArrayHasKey('amount', $response);
70
    }
71
72
    public function testAddVirtualItemToWalletUser()
73
    {
74
        static::$virtualItemSku = uniqid('virtual_item_', false);
75
        //todo refactor:
76
        $virtualItem = static::$xsollaClient->CreateVirtualItem(array(
77
            'project_id' => static::$projectId,
78
            'request' => array(
79
                'sku' => static::$virtualItemSku,
80
                'name' => array(
81
                    'en' => 'Virtual Item',
82
                ),
83
                'description' => array(
84
                    'en' => 'Virtual Item Description',
85
                ),
86
                'prices' => array(
87
                    'USD' => 1,
88
                ),
89
                'default_currency' => 'USD',
90
                'enabled' => true,
91
                'disposable' => false,
92
                'item_type' => 'Consumable',
93
            ),
94
        ));
95
        static::$virtualItemId = $virtualItem['item_id'];
96
97
        static::$xsollaClient->AddVirtualItemToWalletUser(array(
98
            'project_id' => static::$projectId,
99
            'user_id' => static::$userId,
100
            'request' => array(
101
                'virtual_items' => array(
102
                    array(
103
                        'virtual_item' => array(
104
                            'sku' => static::$virtualItemSku,
105
                        ),
106
                        'amount' => 2,
107
                    ),
108
                ),
109
            ),
110
        ));
111
    }
112
113
    /**
114
     * @depends testAddVirtualItemToWalletUser
115
     */
116 View Code Duplication
    public function testListWalletUserVirtualItems()
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...
117
    {
118
        $response = static::$xsollaClient->ListWalletUserVirtualItems(array(
119
            'project_id' => static::$projectId,
120
            'user_id' => static::$userId,
121
            'limit' => 1,
122
            'offset' => 0,
123
        ));
124
        static::assertInternalType('array', $response);
125
    }
126
127
    /**
128
     * @depends testAddVirtualItemToWalletUser
129
     */
130
    public function testDeleteVirtualItemFromWalletUser()
131
    {
132
        static::$xsollaClient->DeleteVirtualItemFromWalletUser(array(
133
            'project_id' => static::$projectId,
134
            'user_id' => static::$userId,
135
            'request' => array(
136
                'virtual_items' => array(
137
                    array(
138
                        'virtual_item' => array(
139
                            'sku' => static::$virtualItemSku,
140
                        ),
141
                        'amount' => 2,
142
                    ),
143
                ),
144
            ),
145
        ));
146
        static::$xsollaClient->DeleteVirtualItem(array(
147
            'project_id' => static::$projectId,
148
            'item_id' => static::$virtualItemId,
149
        ));
150
    }
151
}
152