1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Xsolla\SDK\Tests\Unit\Webhook\Message; |
4
|
|
|
|
5
|
|
|
use Xsolla\SDK\Webhook\Message\UserBalanceMessage; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @group unit |
9
|
|
|
*/ |
10
|
|
|
class UserBalanceMessageTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
protected $request = array( |
13
|
|
|
'virtual_currency_balance' => array( |
14
|
|
|
'old_value' => '0', |
15
|
|
|
'new_value' => '200', |
16
|
|
|
'diff' => '200', |
17
|
|
|
), |
18
|
|
|
'user' => array( |
19
|
|
|
'name' => 'Xsolla User', |
20
|
|
|
'id' => '1234567', |
21
|
|
|
'email' => '[email protected]', |
22
|
|
|
), |
23
|
|
|
'transaction' => array( |
24
|
|
|
'id' => '123456789', |
25
|
|
|
'date' => '2015-05-19T15:54:40+03:00', |
26
|
|
|
), |
27
|
|
|
'operation_type' => 'payment', |
28
|
|
|
'notification_type' => 'user_balance_operation', |
29
|
|
|
'id_operation' => '66989', |
30
|
|
|
'coupon' => array( |
31
|
|
|
'coupon_code' => 'test123', |
32
|
|
|
'campaign_code' => 'Xsolla Campaign', |
33
|
|
|
), |
34
|
|
|
'items_operation_type' => 'add', |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
public function test() |
38
|
|
|
{ |
39
|
|
|
$message = new UserBalanceMessage($this->request); |
40
|
|
|
static::assertSame($this->request['operation_type'], $message->getOperationType()); |
41
|
|
|
static::assertSame($this->request['id_operation'], $message->getOperationId()); |
42
|
|
|
static::assertSame($this->request['coupon'], $message->getCoupon()); |
43
|
|
|
static::assertSame($this->request['virtual_currency_balance'], $message->getVirtualCurrencyBalance()); |
44
|
|
|
static::assertSame($this->request['items_operation_type'], $message->getItemsOperationType()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function testEmptyFields() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$requestCopy = $this->request; |
50
|
|
|
unset( |
51
|
|
|
$requestCopy['virtual_currency_balance'], |
52
|
|
|
$requestCopy['coupon'], |
53
|
|
|
$requestCopy['items_operation_type'] |
54
|
|
|
); |
55
|
|
|
$message = new UserBalanceMessage($requestCopy); |
56
|
|
|
static::assertSame(array(), $message->getCoupon()); |
57
|
|
|
static::assertSame(array(), $message->getVirtualCurrencyBalance()); |
58
|
|
|
static::assertNull($message->getItemsOperationType()); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
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.