Completed
Push — master ( 8bc6ad...b2c48e )
by Vitaliy
16:26 queued 13:19
created

MessageTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 90
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFactory() 0 15 1
A factoryProvider() 0 68 1
1
<?php
2
3
namespace Xsolla\SDK\Tests\Unit\Webhook\Message;
4
5
use Xsolla\SDK\Webhook\Message;
6
7
/**
8
 * @group unit
9
 */
10
class MessageTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @dataProvider factoryProvider
14
     */
15
    public function testFactory($notificationType, $expectedClass, $isUserValidation, $isPayment, $isRefund)
16
    {
17
        $userId = 'USER_ID';
18
        $user = array('id' => 'USER_ID');
19
        $request = array('notification_type' => $notificationType, 'user' => $user);
20
        $message = Message\Message::fromArray($request);
21
        static::assertInstanceOf($expectedClass, $message);
22
        static::assertSame($userId, $message->getUserId());
23
        static::assertSame($user, $message->getUser());
24
        static::assertSame($request, $message->toArray());
25
        static::assertSame($notificationType, $message->getNotificationType());
26
        static::assertSame($isUserValidation, $message->isUserValidation());
27
        static::assertSame($isPayment, $message->isPayment());
28
        static::assertSame($isRefund, $message->isRefund());
29
    }
30
31
    public function factoryProvider()
32
    {
33
        return array(
34
            array(
35
                'notificationType' => 'user_validation',
36
                'expectedClass' => '\Xsolla\SDK\Webhook\Message\UserValidationMessage',
37
                'isUserValidation' => true,
38
                'isPayment' => false,
39
                'isRefund' => false,
40
            ),
41
            array(
42
                'notificationType' => 'payment',
43
                'expectedClass' => '\Xsolla\SDK\Webhook\Message\PaymentMessage',
44
                'isUserValidation' => false,
45
                'isPayment' => true,
46
                'isRefund' => false,
47
            ),
48
            array(
49
                'notificationType' => 'refund',
50
                'expectedClass' => '\Xsolla\SDK\Webhook\Message\RefundMessage',
51
                'isUserValidation' => false,
52
                'isPayment' => false,
53
                'isRefund' => true,
54
            ),
55
            array(
56
                'notificationType' => 'create_subscription',
57
                'expectedClass' => '\Xsolla\SDK\Webhook\Message\CreateSubscriptionMessage',
58
                'isUserValidation' => false,
59
                'isPayment' => false,
60
                'isRefund' => false,
61
            ),
62
            array(
63
                'notificationType' => 'cancel_subscription',
64
                'expectedClass' => '\Xsolla\SDK\Webhook\Message\CancelSubscriptionMessage',
65
                'isUserValidation' => false,
66
                'isPayment' => false,
67
                'isRefund' => false,
68
            ),
69
            array(
70
                'notificationType' => 'update_subscription',
71
                'expectedClass' => '\Xsolla\SDK\Webhook\Message\UpdateSubscriptionMessage',
72
                'isUserValidation' => false,
73
                'isPayment' => false,
74
                'isRefund' => false,
75
            ),
76
            array(
77
                'notificationType' => 'user_balance_operation',
78
                'expectedClass' => '\Xsolla\SDK\Webhook\Message\UserBalanceMessage',
79
                'isUserValidation' => false,
80
                'isPayment' => false,
81
                'isRefund' => false,
82
            ),
83
            array(
84
                'notificationType' => 'get_pincode',
85
                'expectedClass' => '\Xsolla\SDK\Webhook\Message\GetPinCodeMessage',
86
                'isUserValidation' => false,
87
                'isPayment' => false,
88
                'isRefund' => false,
89
            ),
90
            array(
91
                'notificationType' => 'user_search',
92
                'expectedClass' => '\Xsolla\SDK\Webhook\Message\UserSearchMessage',
93
                'isUserValidation' => false,
94
                'isPayment' => false,
95
                'isRefund' => false,
96
            ),
97
        );
98
    }
99
}
100