Completed
Pull Request — master (#37)
by Vitaliy
17:26 queued 07:36
created

WalletTest::testAddVirtualItemToWalletUser()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 39
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

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