mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
refactor test to use public interface instead of protected data by reflection
This commit is contained in:
parent
cf12d976a6
commit
8ec9d8affe
@ -11,6 +11,7 @@ class BaseTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$this->resetProperty('_lang');
|
$this->resetProperty('_lang');
|
||||||
$this->resetProperty('_langDir');
|
$this->resetProperty('_langDir');
|
||||||
|
$this->resetProperty('_rules', array());
|
||||||
$this->resetProperty('_ruleMessages', array());
|
$this->resetProperty('_ruleMessages', array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,19 +17,14 @@ class StaticVsInstanceTest extends BaseTestCase
|
|||||||
public function testRuleMessagesReplacedAfterConstructor()
|
public function testRuleMessagesReplacedAfterConstructor()
|
||||||
{
|
{
|
||||||
$customMessage = 'custom message';
|
$customMessage = 'custom message';
|
||||||
$ruleName = 'foo';
|
$ruleName = 'customRule';
|
||||||
|
$fieldName = 'fieldName';
|
||||||
Validator::addRule($ruleName, function() {}, $customMessage);
|
Validator::addRule($ruleName, function() {}, $customMessage);
|
||||||
|
$v = new Validator(array($fieldName => $fieldName));
|
||||||
$prop = new ReflectionProperty('Valitron\Validator', '_ruleMessages');
|
$v->rule($ruleName, $fieldName);
|
||||||
$prop->setAccessible(true);
|
$v->validate();
|
||||||
$messages = $prop->getValue();
|
$messages = $v->errors();
|
||||||
|
$this->assertArrayHasKey($fieldName, $messages);
|
||||||
$this->assertEquals($customMessage, $messages[$ruleName]);
|
$this->assertEquals(ucfirst("$fieldName $customMessage"), $messages[$fieldName][0]);
|
||||||
|
|
||||||
new Validator(array(), array());
|
|
||||||
|
|
||||||
$messages = $prop->getValue();
|
|
||||||
$this->assertArrayHasKey($ruleName, $messages);
|
|
||||||
$this->assertEquals($customMessage, $messages[$ruleName]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user