|
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()); |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|