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

WalletTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 144
Duplicated Lines 27.78 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 9
c 3
b 0
f 0
lcom 1
cbo 2
dl 40
loc 144
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() 0 9 1
A testListWalletUserOperations() 10 10 1
A testRechargeWalletUserBalance() 12 12 1
B testAddVirtualItemToWalletUser() 0 40 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
    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