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

WalletTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 129
Duplicated Lines 31.01 %

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 129
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 25 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
        $virtualItemTemplate = $this->generateVirtualItemTemplate(static::$virtualItemSku);
76
        $virtualItem = static::$xsollaClient->CreateVirtualItem(array(
77
            'project_id' => static::$projectId,
78
            'request' => $virtualItemTemplate,
79
        ));
80
        static::$virtualItemId = $virtualItem['item_id'];
81
82
        static::$xsollaClient->AddVirtualItemToWalletUser(array(
83
            'project_id' => static::$projectId,
84
            'user_id' => static::$userId,
85
            'request' => array(
86
                'virtual_items' => array(
87
                    array(
88
                        'virtual_item' => array(
89
                            'sku' => static::$virtualItemSku,
90
                        ),
91
                        'amount' => 2,
92
                    ),
93
                ),
94
            ),
95
        ));
96
    }
97
98
    /**
99
     * @depends testAddVirtualItemToWalletUser
100
     */
101 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...
102
    {
103
        $response = static::$xsollaClient->ListWalletUserVirtualItems(array(
104
            'project_id' => static::$projectId,
105
            'user_id' => static::$userId,
106
            'limit' => 1,
107
            'offset' => 0,
108
        ));
109
        static::assertInternalType('array', $response);
110
    }
111
112
    /**
113
     * @depends testAddVirtualItemToWalletUser
114
     */
115
    public function testDeleteVirtualItemFromWalletUser()
116
    {
117
        static::$xsollaClient->DeleteVirtualItemFromWalletUser(array(
118
            'project_id' => static::$projectId,
119
            'user_id' => static::$userId,
120
            'request' => array(
121
                'virtual_items' => array(
122
                    array(
123
                        'virtual_item' => array(
124
                            'sku' => static::$virtualItemSku,
125
                        ),
126
                        'amount' => 2,
127
                    ),
128
                ),
129
            ),
130
        ));
131
        static::$xsollaClient->DeleteVirtualItem(array(
132
            'project_id' => static::$projectId,
133
            'item_id' => static::$virtualItemId,
134
        ));
135
    }
136
}
137