public function testWrongParameterDepth()
 {
     $this->s->str('1_1')->struct('1_3', (new SB())->str('2_1')->struct('2_2', (new SB())->str('3_1')->struct('3_2', (new SB())->struct('4_1', (new SB())->bool('5_1')->int('5_2')))));
     $input = ['1_3' => ['2_2' => ['3_2' => ['4_1' => ['5_1' => 'Not boolean', '5_2' => 'Not integer']]]]];
     $badPaths = ['1_3.2_2.3_2.4_1.5_1', '1_3.2_2.3_2.4_1.5_2'];
     $badFields = [];
     try {
         $this->v->validate($input);
     } catch (InvalidStructureException $e) {
         $badFields = $e->getBadFields();
     }
     foreach ($badPaths as $v) {
         $this->assertTrue(isset($badFields[$v]), 'Field [' . $v . '] should be missing');
     }
 }
Пример #2
0
 /**
  * Validate the given class instance.
  * @return void
  * @throws InvalidStructureException
  */
 public function validate()
 {
     $validator = new StructureValidator($this->getRequest());
     $validator->validate(Input::all());
 }
 public function testEmptyArrayIsValid()
 {
     $this->s->int('numbers')->multiple();
     $input = ['numbers' => []];
     $this->assertTrue($this->v->validate($input), 'Empty array is a valid type');
 }