createValidator($params); foreach ($params as $name => $value) { $this->assertEquals($validator->{$name}, $value); } } /** * Test trying to create a validator with an invalid set of parameters. */ public function testInvalidParams() { $this->expectException('Exception', 'Incorrect option "invalidParam" for validator "'.get_class($this->createValidator()).'".' ); $this->createValidator([ 'invalidParam' => 'value' ]); } /** * Test setting valid parameters individually. * * @dataProvider dataProviderValidParam * * @param array $params */ public function setValidParamSet(array $params) { $validator = $this->createValidator(); foreach ($params as $name => $value) { $validator->{$name} = $value; $this->assertEquals($validator->{$name}, $value); } } /** * Test trying to set an invalid parameter. */ public function testInvalidParamSet() { $this->expectException('Exception', 'Incorrect option "invalidParameter" for validator "'.get_class($this->createValidator()).'".' ); $validator = $this->createValidator(); $validator->invalidParameter = 'value'; } /** * Test validating values that are valid. * * @dataProvider dataProviderValidValues() * * @param array $params * @param $value */ public function testValidateValid(array $params, $value) { $validator = $this->createValidator($params); $result = $validator->validate($value); $this->assertSame(true, $result); $this->assertNull($validator->getError()); } /** * Test validating values that are invalid and check the generated error message. * * @dataProvider dataProviderInvalidValues() * * @param array $params * @param mixed $value * @param string $expectedError */ public function testValidateInvalid(array $params, $value, $expectedError) { $validator = $this->createValidator($params); $result = $validator->validate($value); $this->assertEquals(false, $result); $this->assertSame($expectedError, $validator->getError()); } /** * Test that a correct error message is generated when setting an object name. * * @dataProvider dataProviderInvalidValuesWithObjects() * * @param array $params * @param mixed $value * @param string $expectedError */ public function testValidateInvalidWithObject(array $params, $value, $expectedError) { $validator = $this->createValidator($params); $validator->setObjectName('object'); $result = $validator->validate($value); $this->assertEquals(false, $result); $this->assertSame($expectedError, $validator->getError()); } }