|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OldSound\RabbitMqBundle\Tests\RabbitMq; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
class JsonSchemaTest extends TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
public function testJsonValidatorFunction() |
|
10
|
|
|
{ |
|
11
|
|
|
$jsonValidator = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Validator\JsonValidator') |
|
12
|
|
|
->disableOriginalConstructor() |
|
13
|
|
|
->getMock(); |
|
14
|
|
|
|
|
15
|
|
|
$jsonValidator->setSchema( |
|
16
|
|
|
"OldSound\RabbitMqBundle\TestValidation/schema/JsonValidation.schema", |
|
17
|
|
|
null |
|
18
|
|
|
); |
|
19
|
|
|
|
|
20
|
|
|
$json_msg = <<<'JSON' |
|
21
|
|
|
{ |
|
22
|
|
|
"firstName": "John", |
|
23
|
|
|
"lastName": "Doe", |
|
24
|
|
|
"age": 21 |
|
25
|
|
|
} |
|
26
|
|
|
JSON; |
|
27
|
|
|
$jsonValidator->method('getContentType')->willReturn('application/json'); |
|
28
|
|
|
$this->assertEquals(null, $jsonValidator->validate($json_msg)); |
|
29
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testXmlValidatorFunction() |
|
33
|
|
|
{ |
|
34
|
|
|
$xmlValidator = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Validator\XmlValidator') |
|
35
|
|
|
->disableOriginalConstructor() |
|
36
|
|
|
->getMock(); |
|
37
|
|
|
|
|
38
|
|
|
$xmlValidator->setSchema( |
|
39
|
|
|
"OldSound\RabbitMqBundle\TestValidation/schema/XmlValidation.xsd", |
|
40
|
|
|
null, |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
$xml_msg = <<<'XML' |
|
44
|
|
|
<person> |
|
45
|
|
|
<firstName>John</firstName> |
|
46
|
|
|
<from>Doe</from> |
|
47
|
|
|
<age>21</age> |
|
48
|
|
|
</person> |
|
49
|
|
|
XML; |
|
50
|
|
|
$xmlValidator->method('getContentType')->willReturn('application/xml'); |
|
51
|
|
|
$this->assertEquals(null, $xmlValidator->validate($xml_msg)); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testJsonValidatorWithSchemaDataFunction() |
|
55
|
|
|
{ |
|
56
|
|
|
$jsonValidator = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Validator\JsonValidator') |
|
57
|
|
|
->disableOriginalConstructor() |
|
58
|
|
|
->getMock(); |
|
59
|
|
|
|
|
60
|
|
|
$jsonValidator->setSchema( |
|
61
|
|
|
"OldSound\RabbitMqBundle\TestValidation/schema/top_level.schema", |
|
62
|
|
|
"defs.schema", |
|
63
|
|
|
"OldSound\RabbitMqBundle\TestValidation/schema/common_objects.schema" |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
$json_msg = <<<'JSON' |
|
67
|
|
|
{ |
|
68
|
|
|
"prefix": "Mr", |
|
69
|
|
|
"firstName": "John", |
|
70
|
|
|
"lastName": "Doe", |
|
71
|
|
|
"age": 21, |
|
72
|
|
|
"language": "EN" |
|
73
|
|
|
} |
|
74
|
|
|
JSON; |
|
75
|
|
|
$jsonValidator->method('getContentType')->willReturn('application/json'); |
|
76
|
|
|
$this->assertEquals(null, $jsonValidator->validate($json_msg)); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|