/** * @test * @dataProvider dataToValidate */ public function validate($data, $valid, $errors) { $validationRules = ['title' => ['name' => 'Title', 'required' => true, 'nullable' => true, 'type' => 'string', 'constraints' => ['length' => [1, null]]], 'name' => ['name' => 'Name', 'required' => true, 'type' => 'string', 'constraints' => ['length' => [1, null], 'callback' => [$this, 'callBackTest']]], 'age' => ['name' => 'Age', 'required' => false, 'type' => 'number', 'constraints' => ['integer' => true]], 'address' => ['name' => 'Address', 'required' => false, 'type' => 'object', 'properties' => ['line1' => ['required' => true, 'type' => 'string', 'constraints' => ['length' => [1, null]]], 'line2' => ['required' => false, 'type' => 'string'], 'postCode' => ['required' => true, 'type' => 'string', 'constraints' => ['length' => [3, 12]]]]], 'nickNames' => ['name' => 'Nick Names', 'required' => false, 'type' => 'array', 'items' => ['*' => ['type' => 'string', 'constraints' => ['length' => [1, null]]]]], 'languages' => ['name' => 'Languages', 'required' => false, 'type' => 'array', 'items' => ['*' => ['name' => 'Language', 'type' => 'string', 'constraints' => ['length' => [1, null]]]]], 'favouriteQuote' => ['name' => 'Favourite Quote', 'required' => false, 'nullable' => true, 'type' => 'string', 'constraints' => ['length' => [1, null]]]]; $validator = new Validator(); $this->assertEquals($valid, $validator->isValid($validationRules, $data)); $this->assertEquals($errors, $validator->getErrors()); }
/** * @test */ public function addHasAndGetErrorsWithErrorsSucceed() { $errors = ['test.1' => ['this is an error', 'this is another error'], 'test.2' => ['this is a third error']]; $validator = new Validator(); $validator->addError('test.1', 'this is an error'); $validator->addError('test.1', 'this is another error'); $validator->addError('test.2', 'this is a third error'); $this->assertTrue($validator->hasErrors()); $this->assertEquals($errors, $validator->getErrors()); }