Example #1
0
 function testIncompleteApply()
 {
     $check = new Incomplete\Check(['incompleteExportKey' => 'check', 'incompleteType' => 'foo']);
     $check->apply('foo', $ctx = new Context(['allowIncomplete' => true]));
     $this->assertTrue($ctx->allValid());
     $this->assertFalse($ctx->flatten()->complete);
 }
Example #2
0
 function map($v)
 {
     foreach ($this->checks as $check) {
         $check->apply($v, $ctx = new \Fulfil\Context());
         if ($ctx->allValid()) {
             return $check->map($v);
         }
     }
     return $v;
 }
Example #3
0
 function testDefault()
 {
     $list = new Check\List_(['items' => [new Check\Int_()], 'defaultItem' => new Check\String_()]);
     $list->apply([1], $ctx = new Context());
     $this->assertTrue($ctx->allValid());
     $list->apply([1, '1', '1'], $ctx = new Context());
     $this->assertTrue($ctx->allValid());
     $list->apply([null, null], $ctx = new Context());
     $this->assertTrue($ctx->allValid());
     $list->apply(['1'], $ctx = new Context());
     $flat = $ctx->flatten();
     $this->assertFalse($flat->valid);
     $this->assertCount(1, $flat->messages);
     $this->assertEquals(['int', 'invalidType'], $flat->messages[0]->id);
 }