refactor test to use public interface instead of protected data by reflection

This commit is contained in:
Marcos Neves 2013-08-21 06:38:33 -03:00
parent cf12d976a6
commit 8ec9d8affe
2 changed files with 9 additions and 13 deletions

View File

@ -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());
} }

View File

@ -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]);
} }
} }