Completed
Push — user_validation ( d439b2 )
by
unknown
08:05
created

UserValidationResponseTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 47
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testUserIdHasInvalidType() 0 8 1
A testUserIdIsEmptyString() 0 8 1
A testUserIdIsNull() 0 8 1
A testShortResponseFormat() 0 8 1
A testFullResponseFormat() 0 8 1
1
<?php
2
3
namespace Xsolla\SDK\Tests\Webhook\Message;
4
5
use Xsolla\SDK\Webhook\Response\UserValidationResponse;
6
7
/**
8
 * @group unit
9
 */
10
class UserValidationResponseTest extends \PHPUnit_Framework_TestCase
11
{
12
    public function testUserIdHasInvalidType()
13
    {
14
        $this->setExpectedException(
15
            '\Xsolla\SDK\Exception\Webhook\XsollaWebhookException',
16
            'User id should be non-empty string. stdClass given'
17
        );
18
        new UserValidationResponse(new \StdClass());
0 ignored issues
show
Documentation introduced by
new \StdClass() is of type object<stdClass>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
19
    }
20
21
    public function testUserIdIsEmptyString()
22
    {
23
        $this->setExpectedException(
24
            '\Xsolla\SDK\Exception\Webhook\XsollaWebhookException',
25
            'User id should be non-empty string. Empty string given'
26
        );
27
        new UserValidationResponse('');
28
    }
29
30
    public function testUserIdIsNull()
31
    {
32
        $this->setExpectedException(
33
            '\Xsolla\SDK\Exception\Webhook\XsollaWebhookException',
34
            'User id should be non-empty string. NULL given'
35
        );
36
        new UserValidationResponse(null);
37
    }
38
39
    public function testShortResponseFormat()
40
    {
41
        $response = new UserValidationResponse('user_id');
42
        $this->assertJsonStringEqualsJsonString(
43
            '{"user_id":"user_id"}',
44
            $response->getSymfonyResponse()->getContent()
45
        );
46
    }
47
48
    public function testFullResponseFormat()
49
    {
50
        $response = new UserValidationResponse('user_id', 'user_email', 'user_phone', 'user_country');
51
        $this->assertJsonStringEqualsJsonString(
52
            '{"user_id":"user_id","email":"user_email","phone":"user_phone","country":"user_country"}',
53
            $response->getSymfonyResponse()->getContent()
54
        );
55
    }
56
}
57