public function testJsonStructure() { $array = new ArrayS(); $array->setJsonFormat(__DIR__ . "/resources/testJsonStructure.json"); $res = $array->check(array("id" => 34, "name" => "John", "age" => 18, "marks" => array(8, 7.6, 3, 1, 9, 0, 10, 9.800000000000001, 0.4, 4.5))); $this->assertTrue($res); }
function testFailedRange() { $array = new ArrayS(); $array->setFormat(array("n" => "numeric(-5, 6)[]", "i" => "integer[2,30][]", "f" => "float[-10,-5)")); $correct = array("n" => array("-1", 0.5, 5), "i" => range(2, 30, 1), "f" => -10); $this->assertTrue($array->check($correct, $failed)); $this->assertEquals(array(), $failed); $incorrect1 = array("n" => array(0.5, "a", 5), "i" => range(2, 30, 1), "f" => -10); $this->assertFalse($array->check($incorrect1, $failed)); $this->assertEquals(array("n" => array(1 => "string")), $failed); $incorrect2 = array("n" => array("-1", 0.5, 5), "i" => array(2, 3, 4, 5, 29, 30, 31), "f" => -10); $this->assertFalse($array->check($incorrect2, $failed)); $this->assertEquals(array("i" => array(6 => "integer:range")), $failed); $incorrect3 = array("n" => array("-1", 0.5, 5), "i" => range(2, 30, 1), "f" => false); $this->assertFalse($array->check($incorrect3, $failed)); $this->assertEquals(array("f" => "boolean"), $failed); }