99
1010namespace JsonSchema \Tests \Constraints ;
1111
12+ use JsonSchema \Constraints \Constraint ;
1213use JsonSchema \RefResolver ;
1314use JsonSchema \Uri \UriResolver ;
1415use JsonSchema \Validator ;
@@ -28,8 +29,10 @@ abstract class BaseTestCase extends \PHPUnit_Framework_TestCase
2829 /**
2930 * @dataProvider getInvalidTests
3031 */
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 ())
3233 {
34+ $ checkMode = $ checkMode === null ? Constraint::CHECK_MODE_NORMAL : $ checkMode ;
35+
3336 $ schema = json_decode ($ jsonSchema );
3437 if (is_object ($ schema )) {
3538 $ schema = $ this ->resolveSchema ($ schema );
@@ -46,10 +49,36 @@ public function testInvalidCases($input, $jsonSchema, $checkMode = Validator::CH
4649 $ this ->assertFalse ($ validator ->isValid (), print_r ($ validator ->getErrors (), true ));
4750 }
4851
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+
4978 /**
5079 * @dataProvider getValidTests
5180 */
52- public function testValidCases ($ input , $ schema , $ checkMode = Validator ::CHECK_MODE_NORMAL )
81+ public function testValidCases ($ input , $ schema , $ checkMode = Constraint ::CHECK_MODE_NORMAL )
5382 {
5483 $ schema = json_decode ($ schema );
5584 if (is_object ($ schema )) {
@@ -63,16 +92,53 @@ public function testValidCases($input, $schema, $checkMode = Validator::CHECK_MO
6392 $ this ->assertTrue ($ validator ->isValid (), print_r ($ validator ->getErrors (), true ));
6493 }
6594
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+
66116 /**
67117 * @return array[]
68118 */
69119 abstract public function getValidTests ();
70120
121+ /**
122+ * @return array[]
123+ */
124+ public function getValidForAssocTests ()
125+ {
126+ return $ this ->getValidTests ();
127+ }
128+
71129 /**
72130 * @return array[]
73131 */
74132 abstract public function getInvalidTests ();
75133
134+ /**
135+ * @return array[]
136+ */
137+ public function getInvalidForAssocTests ()
138+ {
139+ return $ this ->getInvalidTests ();
140+ }
141+
76142 /**
77143 * @param object $schema
78144 * @return object
0 commit comments