/** @dataProvider dataValid */ function testIterableValid($in) { $iter = new Iterable(); $out = $iter->apply($in, $ctx = new \Fulfil\Context()); $this->assertSame($in, $out); $this->assertTrue($ctx->flatten()->valid); }
function testArrayUnique() { $check = new Array_(['unique' => true]); $in = [1, 2, 2]; $out = $check->apply($in, $ctx = new \Fulfil\Context()); $this->assertSame($in, $out); $flat = $ctx->flatten(); $this->assertFalse($flat->valid); $this->assertCount(1, $flat->messages); $this->assertEquals(['array', 'unique'], $flat->messages[0]->id); }
function testMessageText() { $check = $this->createCheckForStandardTests(['required' => true, 'message' => ['text' => 'nope']]); $input = null; $output = $check->apply($input, $ctx = new \Fulfil\Context()); $this->assertSame($input, $output); $flat = $ctx->flatten(); $this->assertFalse($flat->valid); $this->assertCount(1, $flat->messages); $this->assertEquals('nope', $flat->messages[0]->text); }
function testSelfChecker() { $class = ClassBuilder::i()->registerOne(' class Pants implements \\Fulfil\\Lang\\SelfChecker { function check(\\Fulfil\\Context $ctx) { $ctx->addReason($this, ["id"=>"nope"]); } } '); $obj = new $class(); $check = new Instance(['class' => $class]); $ret = $check->apply($obj, $ctx = new \Fulfil\Context()); $this->assertSame($obj, $ret); $flat = $ctx->flatten(); $this->assertFalse($flat->valid); $this->assertCount(1, $flat->messages); $this->assertEquals(['nope'], $flat->messages[0]->id); }
function testNames() { $check = new \Fulfil\Check\Basic(); $ctx = new \Fulfil\Context(); $ctx->push('a', 'A'); $ctx->push('b', ''); // name is inferred from path when not provided $ctx->addReason($check, ['id' => 'check.nup']); $ctx->push('c', 'C'); $ctx->addReason($check, ['id' => 'check.nup']); $sms = new \Fulfil\MessageSet\SimpleTemplate(['field' => ['a.b' => '12', 'a.b.c' => '123'], 'default' => 'default']); $messages = $sms->formatContext($ctx); $this->assertEquals(['A > b: 12', 'A > b > C: 123'], $messages); $messages = $sms->formatContext($ctx, 'a.b'); $this->assertEquals(['12', 'C: 123'], $messages); }
function testSchemaMapperPopulateWithUnknownProperty() { $class = ClassBuilder::i()->registerOne(' class PropObj { public $foo = "a"; public $bar = "b"; public function populate($in) { foreach ($in as $k=>$v) { if (!isset($this->$k)) { throw new \\Exception(); } $this->$k = $v; } } } '); $schema = new Schema(['props' => ['foo' => new Check\String_(), 'bar' => new Check\String_()], 'filterUnknownProps' => true]); $in = ['foo' => 'yep', 'bar' => 'yep', 'baz' => 'yep']; $out = $schema->apply($in, $ctx = new \Fulfil\Context()); $flat = $ctx->flatten(); $this->assertFalse($flat->valid); $this->assertCount(1, $flat->messages); $this->assertEquals(['schema', 'propUnknown'], $flat->messages[0]->id); $obj = new $class(); $obj->populate($out); }