public function testThePatternWillFailIfRequiredKeyDoesNotExist() { $sut = new HasTypeMap(['foo' => 'string']); $this->assertFalse($sut->isValid([])); $this->assertEquals('Value key:foo does not exist: Value has invalid type map', implode(': ', $sut->getMessages())); }
<?php /** * Validation * * @author Ashley Kitson * @copyright Ashley Kitson, 2015, UK * @license GPL V3+ See LICENSE.md */ require_once '../vendor/autoload.php'; use Chippyash\Validation\Pattern\HasTypeMap; use Chippyash\Validation\Pattern\Repeater; use Chippyash\Validation\Common\ISO8601DateString; use Chippyash\Validation\Common\Email; use Chippyash\Validation\Common\UKPostCode; use Chippyash\Type\Number\IntType; $validator = new HasTypeMap(['a' => new ISO8601DateString(), 'b' => 'boolean', 'c' => new Repeater(new HasTypeMap(['d' => 'string', 'e' => new UKPostCode()]), null, new IntType(4)), 'f' => new Repeater(new Email())]); $json = <<<EOT { "a": "2015-12-01", "b": false, "c": [ { "d": "fred", "e": "NN10 6HB" }, { "d": "jim", "e": "EC1V 7DA" }, { "d": "maggie",