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

PaymentMessageTest::test()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Xsolla\SDK\Tests\Unit\Webhook\Message;
4
5
use Xsolla\SDK\Webhook\Message\PaymentMessage;
6
7
/**
8
 * @group unit
9
 */
10
class PaymentMessageTest extends \PHPUnit_Framework_TestCase
11
{
12
    protected $request = array(
13
        'notification_type' => 'payment',
14
        'purchase' => array(
15
                'virtual_currency' => array(
16
                        'name' => 'Coins',
17
                        'quantity' => 10,
18
                        'currency' => 'USD',
19
                        'amount' => 100,
20
                    ),
21
                'subscription' => array(
22
                        'plan_id' => 1,
23
                        'subscription_id' => '10',
24
                        'product_id' => 'Demo Product',
25
                        'date_create' => '2014-09-22T19:25:25+04:00',
26
                        'currency' => 'USD',
27
                        'amount' => 9.99,
28
                    ),
29
                'checkout' => array(
30
                        'currency' => 'USD',
31
                        'amount' => 50,
32
                    ),
33
                'virtual_items' => array(
34
                        'items' => array(
35
                                0 => array(
36
                                        'sku' => 'test_item1',
37
                                        'amount' => 1,
38
                                    ),
39
                            ),
40
                        'currency' => 'USD',
41
                        'amount' => 50,
42
                    ),
43
                'total' => array(
44
                        'currency' => 'USD',
45
                        'amount' => 200,
46
                    ),
47
                'promotions[0]' => array(
48
                        'technical_name' => 'Demo Promotion',
49
                        'id' => '853',
50
                    ),
51
                'coupon' => array(
52
                        'coupon_code' => 'ICvj45S4FUOyy',
53
                        'campaign_code' => '1507',
54
                    ),
55
        ),
56
        'user' => array(
57
                'ip' => '127.0.0.1',
58
                'phone' => '18777976552',
59
                'email' => '[email protected]',
60
                'id' => '1234567',
61
                'name' => 'Xsolla User',
62
                'country' => 'US',
63
        ),
64
        'transaction' => array(
65
                'id' => 1,
66
                'external_id' => 1,
67
                'payment_date' => '2014-09-24T20:38:16+04:00',
68
                'payment_method' => 1,
69
                'dry_run' => 1,
70
                'agreement' => 1,
71
        ),
72
        'payment_details' => array(
73
                'payment' => array(
74
                        'currency' => 'USD',
75
                        'amount' => 230,
76
                    ),
77
                'vat' => array(
78
                        'currency' => 'USD',
79
                        'amount' => 0,
80
                    ),
81
                'payout_currency_rate' => 1,
82
                'payout' => array(
83
                        'currency' => 'USD',
84
                        'amount' => 200,
85
                    ),
86
                'xsolla_fee' => array(
87
                        'currency' => 'USD',
88
                        'amount' => 10,
89
                    ),
90
                'payment_method_fee' => array(
91
                        'currency' => 'USD',
92
                        'amount' => 20,
93
                    ),
94
        ),
95
        'custom_parameters' => array(
96
                'parameter1' => 'value1',
97
                'parameter2' => 'value2',
98
        ),
99
    );
100
101
    public function test()
102
    {
103
        $message = new PaymentMessage($this->request);
104
        static::assertSame($this->request['purchase'], $message->getPurchase());
105
        static::assertSame($this->request['transaction'], $message->getTransaction());
106
        static::assertSame($this->request['transaction']['id'], $message->getPaymentId());
107
        static::assertSame($this->request['transaction']['external_id'], $message->getExternalPaymentId());
108
        static::assertSame($this->request['payment_details'], $message->getPaymentDetails());
109
        static::assertSame($this->request['custom_parameters'], $message->getCustomParameters());
110
        static::assertTrue($message->isDryRun());
111
    }
112
113 View Code Duplication
    public function testEmptyFields()
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...
114
    {
115
        $requestCopy = $this->request;
116
        unset(
117
            $requestCopy['custom_parameters'],
118
            $requestCopy['transaction']['dry_run'],
119
            $requestCopy['transaction']['external_id']
120
        );
121
        $message = new PaymentMessage($requestCopy);
122
123
        static::assertNull($message->getExternalPaymentId());
124
        static::assertSame(array(), $message->getCustomParameters());
125
        static::assertFalse($message->isDryRun());
126
    }
127
}
128