Example #1
0
 public function testFull()
 {
     $string = '{"User":{"Name":"Bob","Tags":["lazy","scruffy"]}}';
     //test that decoding and re-encoding returns the original content
     $this->assertEquals(JSON::encode(JSON::decode($string)), $string);
     //test that the zend and pecl/json decoders return the same result
     $this->assertEquals(JSON::decode($string, JSON::CODER_JSON), JSON::decode($string, JSON::CODER_ZEND));
     //test that the zend and pecl/json encoders return the same result
     $string = JSON::decode($string);
     $this->assertEquals(JSON::encode($string, JSON::CODER_JSON), JSON::encode($string, JSON::CODER_ZEND));
 }
Example #2
0
 public function testValidateMaxDecNumber()
 {
     $schema = '{"description":"An Object with numbers",' . '"type":"object",' . '"properties":{' . '"number0":{"type":"number","maxDecimal":4},' . '"number1":{"type":"number","maxDecimal":4}' . '}' . '}';
     $json = '{"number0":50.3333,"number1":50.33333}';
     $expected = array('valid' => false, 'errors' => array(array('property' => '.number1', 'message' => 'Must not exceed 4 decimal places')));
     $jd = I\JSON::decode($json);
     $sd = I\JSON::decode($schema);
     $return = Schema::validate($jd, $sd);
     $this->assertEquals($expected, $return);
 }