Example #1
0
 public function testStaticArrayS()
 {
     $format = array("int[5]", "float[5]", "bool");
     $array = \Structure\Structure::ArrayS($format);
     $data = array(range(1, 5), range(1.2, 2, 0.2), true);
     $this->assertTrue($array->check($data));
 }
Example #2
0
 public function testFormat3()
 {
     $format = array("full_name" => "string", "height" => "integer", "weight" => "integer", "gender" => "integer[0,2]");
     $formatter = \Structure\Structure::ArrayS($format, null, false, true);
     $array = array("full_name" => "My Name", "height" => 175, "gender" => "-1");
     $this->assertFalse($formatter->check($array));
     $newArray = $formatter->format($array);
     $this->assertTrue($formatter->check($newArray));
 }
Example #3
0
 function testScalarFail()
 {
     Structure::clearLastFail();
     $this->assertEquals(null, Structure::getLastFail());
     $scalar = new ScalarS();
     foreach (array("hello world", 12, true, false, 1.3, "1.2") as $s) {
         $this->assertTrue($scalar->check($s));
         $this->assertEquals(null, Structure::getLastFail());
     }
     $this->assertFalse($scalar->check(array()));
     $this->assertEquals("array", Structure::getLastFail());
     $this->assertFalse($scalar->check(function () {
     }));
     $this->assertEquals("closure", Structure::getLastFail());
     $this->assertFalse($scalar->check(new Test()));
     $this->assertEquals("object", Structure::getLastFail());
 }
Example #4
0
 public function testEmptyArrayDescription()
 {
     $checker = \Structure\Structure::ArrayS("[0]");
     $this->assertTrue($checker->check(array()));
     $this->assertFalse($checker->check(array("abc")));
     $this->assertFalse($checker->check(array(null)));
     $this->assertFalse($checker->check("abc"));
 }
Example #5
0
 public function testBadInfinities()
 {
     try {
         $numeric = \Structure\Structure::NumericS("(inf, 0)");
         $this->fail("An exception was excepted");
     } catch (\Exception $e) {
         $this->addToAssertionCount(1);
     }
     try {
         $numeric = \Structure\Structure::NumericS("(0,-inf)");
         $this->fail("An exception was excepted");
     } catch (\Exception $e) {
         $this->addToAssertionCount(1);
     }
 }