예제 #1
0
 public function testCustomFilters()
 {
     JsonType::addCustomFilter('slug', function ($value) {
         return strpos($value, ' ') === false;
     });
     $jsonType = new JsonType(['title' => 'have a test', 'slug' => 'have-a-test']);
     $this->assertTrue($jsonType->matches(['slug' => 'string:slug']));
     $this->assertNotTrue($jsonType->matches(['title' => 'string:slug']));
     JsonType::addCustomFilter('/len\\((.*?)\\)/', function ($value, $len) {
         return strlen($value) == $len;
     });
     $this->assertTrue($jsonType->matches(['slug' => 'string:len(11)']));
     $this->assertNotTrue($jsonType->matches(['slug' => 'string:len(7)']));
 }
예제 #2
0
 public function testCustomFilters()
 {
     JsonType::addCustomFilter('email', function ($value) {
         return strpos($value, '@') !== false;
     });
     $jsonType = new JsonType(['email' => '*****@*****.**', 'name' => 'davert']);
     $this->assertTrue($jsonType->matches(['email' => 'string:email']));
     $this->assertNotTrue($jsonType->matches(['name' => 'string:email']));
     JsonType::addCustomFilter('/len\\((.*?)\\)/', function ($value, $len) {
         return strlen($value) == $len;
     });
     $this->assertTrue($jsonType->matches(['email' => 'string:len(22)']));
     $this->assertNotTrue($jsonType->matches(['email' => 'string:len(7)']));
 }