UserSearchResponseTest::testUserIdIsEmptyString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Xsolla\SDK\Tests\Unit\Webhook\Message;
4
5
use PHPUnit\Framework\TestCase;
6
use Xsolla\SDK\Webhook\Response\UserResponse;
7
use Xsolla\SDK\Webhook\User;
8
9
/**
10
 * @group unit
11
 */
12
class UserSearchResponseTest extends TestCase
13
{
14
    public function testUserIdHasInvalidType()
15
    {
16
        $this->expectException('\Xsolla\SDK\Exception\Webhook\XsollaWebhookException');
17
        $this->expectExceptionMessage('User id should be non-empty string. stdClass given');
18
19
        $user = new User();
20
        new UserResponse($user->setId(new \stdClass()));
21
    }
22
23
    public function testUserIdIsEmptyString()
24
    {
25
        $this->expectException('\Xsolla\SDK\Exception\Webhook\XsollaWebhookException');
26
        $this->expectExceptionMessage('User id should be non-empty string. Empty string given');
27
28
        $user = new User();
29
        new UserResponse($user->setId(''));
30
    }
31
32
    public function testUserIdIsNull()
33
    {
34
        $this->expectException('\Xsolla\SDK\Exception\Webhook\XsollaWebhookException');
35
        $this->expectExceptionMessage('User id should be non-empty string. NULL given');
36
37
        new UserResponse(new User());
38
    }
39
40
    public function testShortResponseFormat()
41
    {
42
        $user = new User();
43
        $response = new UserResponse($user->setId('user_id'));
44
45
        $this->assertJsonStringEqualsJsonString('{"user":{"id":"user_id"}}', $response->getSymfonyResponse()->getContent());
0 ignored issues
show
Security Bug introduced by
It seems like $response->getSymfonyResponse()->getContent() targeting Symfony\Component\HttpFo...\Response::getContent() can also be of type false; however, PHPUnit\Framework\Assert...tringEqualsJsonString() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
46
    }
47
48
    public function testFullResponseFormat()
49
    {
50
        $user = new User();
51
        $user->setId('user_id');
52
        $user->setEmail('user_email');
53
        $user->setPhone('user_phone');
54
        $user->setName('user_name');
55
        $user->setPublicId('user_public_id');
56
57
        $response = new UserResponse($user);
58
59
        $this->assertJsonStringEqualsJsonString(
60
            '{"user":{"id":"user_id","email":"user_email","phone":"user_phone","name":"user_name","public_id":"user_public_id"}}',
61
            $response->getSymfonyResponse()->getContent()
0 ignored issues
show
Security Bug introduced by
It seems like $response->getSymfonyResponse()->getContent() targeting Symfony\Component\HttpFo...\Response::getContent() can also be of type false; however, PHPUnit\Framework\Assert...tringEqualsJsonString() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
62
        );
63
    }
64
}
65