Skip to content

Commit 2366f30

Browse files
committed
add invalid cases to UriRetrieverTest, making the Test fail
1 parent f215683 commit 2366f30

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

tests/JsonSchema/Tests/Uri/UriRetrieverTest.php

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,69 @@ protected function setUp()
1919
{
2020
$this->validator = new Validator();
2121
}
22-
22+
2323
private function getRetrieverMock($returnSchema, $returnMediaType = Validator::SCHEMA_MEDIA_TYPE)
2424
{
2525
$retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('retrieve'));
26-
26+
2727
$retriever->expects($this->at(0))
2828
->method('retrieve')
2929
->with($this->equalTo(null), $this->equalTo('http://some.host.at/somewhere/parent'))
3030
->will($this->returnValue($returnSchema));
31-
31+
3232
return $retriever;
3333
}
34-
34+
3535
/**
36-
* @dataProvider jsonProvider
36+
* @dataProvider jsonProvider
3737
*/
38-
public function testChildExtendsParent($childSchema, $parentSchema)
38+
public function testChildExtendsParentValidTest($childSchema, $parentSchema)
3939
{
4040
$retrieverMock = $this->getRetrieverMock($parentSchema);
41-
41+
4242
$json = '{"childProp":"infant", "parentProp":false}';
4343
$decodedJson = json_decode($json);
4444
$decodedJsonSchema = json_decode($childSchema);
45-
45+
4646
$this->validator->setUriRetriever($retrieverMock);
4747
$this->validator->check($decodedJson, $decodedJsonSchema);
4848
$this->assertTrue($this->validator->isValid());
4949
}
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+
5167
/**
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
5385
*/
5486
public function testResolveRelativeUri($childSchema, $parentSchema)
5587
{
@@ -58,24 +90,24 @@ public function testResolveRelativeUri($childSchema, $parentSchema)
5890
$json = '{"childProp":"infant", "parentProp":false}';
5991
$decodedJson = json_decode($json);
6092
$decodedJsonSchema = json_decode($childSchema);
61-
93+
6294
$this->validator->setUriRetriever($retrieverMock);
6395
$this->validator->check($decodedJson, $decodedJsonSchema);
6496
$this->assertTrue($this->validator->isValid());
6597
}
66-
98+
6799
private static function setParentSchemaExtendsValue(&$parentSchema, $value)
68100
{
69101
$parentSchemaDecoded = json_decode($parentSchema, true);
70102
$parentSchemaDecoded['extends'] = $value;
71103
$parentSchema = json_encode($parentSchemaDecoded);
72104
}
73-
105+
74106
public function jsonProvider()
75107
{
76108
$childSchema = <<<EOF
77109
{
78-
"type":"object",
110+
"type":"object",
79111
"title":"child",
80112
"extends":"http://some.host.at/somewhere/parent",
81113
"properties":
@@ -89,7 +121,7 @@ public function jsonProvider()
89121
EOF;
90122
$parentSchema = <<<EOF
91123
{
92-
"type":"object",
124+
"type":"object",
93125
"title":"parent",
94126
"properties":
95127
{

0 commit comments

Comments
 (0)