@@ -19,37 +19,69 @@ protected function setUp()
19
19
{
20
20
$ this ->validator = new Validator ();
21
21
}
22
-
22
+
23
23
private function getRetrieverMock ($ returnSchema , $ returnMediaType = Validator::SCHEMA_MEDIA_TYPE )
24
24
{
25
25
$ retriever = $ this ->getMock ('JsonSchema\Uri\UriRetriever ' , array ('retrieve ' ));
26
-
26
+
27
27
$ retriever ->expects ($ this ->at (0 ))
28
28
->method ('retrieve ' )
29
29
->with ($ this ->equalTo (null ), $ this ->equalTo ('http://some.host.at/somewhere/parent ' ))
30
30
->will ($ this ->returnValue ($ returnSchema ));
31
-
31
+
32
32
return $ retriever ;
33
33
}
34
-
34
+
35
35
/**
36
- * @dataProvider jsonProvider
36
+ * @dataProvider jsonProvider
37
37
*/
38
- public function testChildExtendsParent ($ childSchema , $ parentSchema )
38
+ public function testChildExtendsParentValidTest ($ childSchema , $ parentSchema )
39
39
{
40
40
$ retrieverMock = $ this ->getRetrieverMock ($ parentSchema );
41
-
41
+
42
42
$ json = '{"childProp":"infant", "parentProp":false} ' ;
43
43
$ decodedJson = json_decode ($ json );
44
44
$ decodedJsonSchema = json_decode ($ childSchema );
45
-
45
+
46
46
$ this ->validator ->setUriRetriever ($ retrieverMock );
47
47
$ this ->validator ->check ($ decodedJson , $ decodedJsonSchema );
48
48
$ this ->assertTrue ($ this ->validator ->isValid ());
49
49
}
50
-
50
+
51
+ /**
52
+ * @dataProvider jsonProvider
53
+ */
54
+ public function testChildExtendsParentInvalidChildTest ($ childSchema , $ parentSchema )
55
+ {
56
+ $ retrieverMock = $ this ->getRetrieverMock ($ parentSchema );
57
+
58
+ $ json = '{"childProp":1, "parentProp":false} ' ;
59
+ $ decodedJson = json_decode ($ json );
60
+ $ decodedJsonSchema = json_decode ($ childSchema );
61
+
62
+ $ this ->validator ->setUriRetriever ($ retrieverMock );
63
+ $ this ->validator ->check ($ decodedJson , $ decodedJsonSchema );
64
+ $ this ->assertFalse ($ this ->validator ->isValid ());
65
+ }
66
+
51
67
/**
52
- * @dataProvider jsonProvider
68
+ * @dataProvider jsonProvider
69
+ */
70
+ public function testChildExtendsParentInvalidParentTest ($ childSchema , $ parentSchema )
71
+ {
72
+ $ retrieverMock = $ this ->getRetrieverMock ($ parentSchema );
73
+
74
+ $ json = '{"childProp":"infant", "parentProp":1} ' ;
75
+ $ decodedJson = json_decode ($ json );
76
+ $ decodedJsonSchema = json_decode ($ childSchema );
77
+
78
+ $ this ->validator ->setUriRetriever ($ retrieverMock );
79
+ $ this ->validator ->check ($ decodedJson , $ decodedJsonSchema );
80
+ $ this ->assertFalse ($ this ->validator ->isValid ());
81
+ }
82
+
83
+ /**
84
+ * @dataProvider jsonProvider
53
85
*/
54
86
public function testResolveRelativeUri ($ childSchema , $ parentSchema )
55
87
{
@@ -58,24 +90,24 @@ public function testResolveRelativeUri($childSchema, $parentSchema)
58
90
$ json = '{"childProp":"infant", "parentProp":false} ' ;
59
91
$ decodedJson = json_decode ($ json );
60
92
$ decodedJsonSchema = json_decode ($ childSchema );
61
-
93
+
62
94
$ this ->validator ->setUriRetriever ($ retrieverMock );
63
95
$ this ->validator ->check ($ decodedJson , $ decodedJsonSchema );
64
96
$ this ->assertTrue ($ this ->validator ->isValid ());
65
97
}
66
-
98
+
67
99
private static function setParentSchemaExtendsValue (&$ parentSchema , $ value )
68
100
{
69
101
$ parentSchemaDecoded = json_decode ($ parentSchema , true );
70
102
$ parentSchemaDecoded ['extends ' ] = $ value ;
71
103
$ parentSchema = json_encode ($ parentSchemaDecoded );
72
104
}
73
-
105
+
74
106
public function jsonProvider ()
75
107
{
76
108
$ childSchema = <<<EOF
77
109
{
78
- "type":"object",
110
+ "type":"object",
79
111
"title":"child",
80
112
"extends":"http://some.host.at/somewhere/parent",
81
113
"properties":
@@ -89,7 +121,7 @@ public function jsonProvider()
89
121
EOF ;
90
122
$ parentSchema = <<<EOF
91
123
{
92
- "type":"object",
124
+ "type":"object",
93
125
"title":"parent",
94
126
"properties":
95
127
{
0 commit comments