9
9
10
10
namespace JsonSchema \Tests \Constraints ;
11
11
12
+ use JsonSchema \Constraints \Constraint ;
12
13
use JsonSchema \RefResolver ;
13
14
use JsonSchema \Uri \UriResolver ;
14
15
use JsonSchema \Validator ;
@@ -28,8 +29,10 @@ abstract class BaseTestCase extends \PHPUnit_Framework_TestCase
28
29
/**
29
30
* @dataProvider getInvalidTests
30
31
*/
31
- public function testInvalidCases ($ input , $ jsonSchema , $ checkMode = Validator ::CHECK_MODE_NORMAL , $ errors = array ())
32
+ public function testInvalidCases ($ input , $ jsonSchema , $ checkMode = Constraint ::CHECK_MODE_NORMAL , $ errors = array ())
32
33
{
34
+ $ checkMode = $ checkMode === null ? Constraint::CHECK_MODE_NORMAL : $ checkMode ;
35
+
33
36
$ schema = json_decode ($ jsonSchema );
34
37
if (is_object ($ schema )) {
35
38
$ schema = $ this ->resolveSchema ($ schema );
@@ -46,10 +49,36 @@ public function testInvalidCases($input, $jsonSchema, $checkMode = Validator::CH
46
49
$ this ->assertFalse ($ validator ->isValid (), print_r ($ validator ->getErrors (), true ));
47
50
}
48
51
52
+ /**
53
+ * @dataProvider getInvalidForAssocTests
54
+ */
55
+ public function testInvalidCasesUsingAssoc ($ input , $ jsonSchema , $ checkMode = Constraint::CHECK_MODE_TYPE_CAST , $ errors = array ())
56
+ {
57
+ $ checkMode = $ checkMode === null ? Constraint::CHECK_MODE_TYPE_CAST : $ checkMode ;
58
+ if ($ checkMode !== Constraint::CHECK_MODE_TYPE_CAST ) {
59
+ $ this ->markTestSkipped ('Test indicates that it is not for "CHECK_MODE_TYPE_CAST" ' );
60
+ }
61
+
62
+ $ schema = json_decode ($ jsonSchema );
63
+ if (is_object ($ schema )) {
64
+ $ schema = $ this ->resolveSchema ($ schema );
65
+ }
66
+
67
+ $ value = json_decode ($ input , true );
68
+
69
+ $ validator = new Validator ($ checkMode );
70
+ $ validator ->check ($ value , $ schema );
71
+
72
+ if (array () !== $ errors ) {
73
+ $ this ->assertEquals ($ errors , $ validator ->getErrors (), print_r ($ validator ->getErrors (), true ));
74
+ }
75
+ $ this ->assertFalse ($ validator ->isValid (), print_r ($ validator ->getErrors (), true ));
76
+ }
77
+
49
78
/**
50
79
* @dataProvider getValidTests
51
80
*/
52
- public function testValidCases ($ input , $ schema , $ checkMode = Validator ::CHECK_MODE_NORMAL )
81
+ public function testValidCases ($ input , $ schema , $ checkMode = Constraint ::CHECK_MODE_NORMAL )
53
82
{
54
83
$ schema = json_decode ($ schema );
55
84
if (is_object ($ schema )) {
@@ -63,16 +92,53 @@ public function testValidCases($input, $schema, $checkMode = Validator::CHECK_MO
63
92
$ this ->assertTrue ($ validator ->isValid (), print_r ($ validator ->getErrors (), true ));
64
93
}
65
94
95
+ /**
96
+ * @dataProvider getValidForAssocTests
97
+ */
98
+ public function testValidCasesUsingAssoc ($ input , $ schema , $ checkMode = Constraint::CHECK_MODE_TYPE_CAST )
99
+ {
100
+ if ($ checkMode !== Constraint::CHECK_MODE_TYPE_CAST ) {
101
+ $ this ->markTestSkipped ('Test indicates that it is not for "CHECK_MODE_TYPE_CAST" ' );
102
+ }
103
+
104
+ $ schema = json_decode ($ schema );
105
+ if (is_object ($ schema )) {
106
+ $ schema = $ this ->resolveSchema ($ schema );
107
+ }
108
+
109
+ $ value = json_decode ($ input , true );
110
+ $ validator = new Validator ($ checkMode );
111
+
112
+ $ validator ->check ($ value , $ schema );
113
+ $ this ->assertTrue ($ validator ->isValid (), print_r ($ validator ->getErrors (), true ));
114
+ }
115
+
66
116
/**
67
117
* @return array[]
68
118
*/
69
119
abstract public function getValidTests ();
70
120
121
+ /**
122
+ * @return array[]
123
+ */
124
+ public function getValidForAssocTests ()
125
+ {
126
+ return $ this ->getValidTests ();
127
+ }
128
+
71
129
/**
72
130
* @return array[]
73
131
*/
74
132
abstract public function getInvalidTests ();
75
133
134
+ /**
135
+ * @return array[]
136
+ */
137
+ public function getInvalidForAssocTests ()
138
+ {
139
+ return $ this ->getInvalidTests ();
140
+ }
141
+
76
142
/**
77
143
* @param object $schema
78
144
* @return object
0 commit comments