Completed
Pull Request — master (#37)
by Vitaliy
06:49 queued 04:18
created

WalletTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 143
Duplicated Lines 34.27 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 9
c 3
b 1
f 0
lcom 1
cbo 2
dl 49
loc 143
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateWalletUser() 0 4 1
A testGetWalletUser() 8 8 1
A testUpdateWalletUser() 0 10 1
A testListWalletUsers() 9 9 1
A testListWalletUserOperations() 10 10 1
A testRechargeWalletUserBalance() 12 12 1
B testAddVirtualItemToWalletUser() 0 39 1
A testListWalletUserVirtualItems() 10 10 1
A testDeleteVirtualItemFromWalletUser() 0 21 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 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...
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
        $virtualItem = static::$xsollaClient->CreateVirtualItem(array(
76
            'project_id' => static::$projectId,
77
            'request' => array(
78
                'sku' => static::$virtualItemSku,
79
                'name' => array(
80
                    'en' => 'Virtual Item',
81
                ),
82
                'description' => array(
83
                    'en' => 'Virtual Item Description',
84
                ),
85
                'prices' => array(
86
                    'USD' => 1,
87
                ),
88
                'default_currency' => 'USD',
89
                'enabled' => true,
90
                'disposable' => false,
91
                'item_type' => 'Consumable',
92
            ),
93
        ));
94
        static::$virtualItemId = $virtualItem['item_id'];
95
96
        static::$xsollaClient->AddVirtualItemToWalletUser(array(
97
            'project_id' => static::$projectId,
98
            'user_id' => static::$userId,
99
            'request' => array(
100
                'virtual_items' => array(
101
                    array(
102
                        'virtual_item' => array(
103
                            'sku' => static::$virtualItemSku,
104
                        ),
105
                        'amount' => 2,
106
                    ),
107
                ),
108
            ),
109
        ));
110
    }
111
112
    /**
113
     * @depends testAddVirtualItemToWalletUser
114
     */
115 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...
116
    {
117
        $response = static::$xsollaClient->ListWalletUserVirtualItems(array(
118
            'project_id' => static::$projectId,
119
            'user_id' => static::$userId,
120
            'limit' => 1,
121
            'offset' => 0,
122
        ));
123
        static::assertInternalType('array', $response);
124
    }
125
126
    /**
127
     * @depends testAddVirtualItemToWalletUser
128
     */
129
    public function testDeleteVirtualItemFromWalletUser()
130
    {
131
        static::$xsollaClient->DeleteVirtualItemFromWalletUser(array(
132
            'project_id' => static::$projectId,
133
            'user_id' => static::$userId,
134
            'request' => array(
135
                'virtual_items' => array(
136
                    array(
137
                        'virtual_item' => array(
138
                            'sku' => static::$virtualItemSku,
139
                        ),
140
                        'amount' => 2,
141
                    ),
142
                ),
143
            ),
144
        ));
145
        static::$xsollaClient->DeleteVirtualItem(array(
146
            'project_id' => static::$projectId,
147
            'item_id' => static::$virtualItemId,
148
        ));
149
    }
150
}
151