From 8ec9d8affe0efbdcb41395575a126ee8bfc54d79 Mon Sep 17 00:00:00 2001 From: Marcos Neves Date: Wed, 21 Aug 2013 06:38:33 -0300 Subject: [PATCH] refactor test to use public interface instead of protected data by reflection --- tests/Valitron/BaseTestCase.php | 1 + tests/Valitron/StaticVsInstanceTest.php | 21 ++++++++------------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/Valitron/BaseTestCase.php b/tests/Valitron/BaseTestCase.php index 0dec6c4..9754f01 100644 --- a/tests/Valitron/BaseTestCase.php +++ b/tests/Valitron/BaseTestCase.php @@ -11,6 +11,7 @@ class BaseTestCase extends \PHPUnit_Framework_TestCase { $this->resetProperty('_lang'); $this->resetProperty('_langDir'); + $this->resetProperty('_rules', array()); $this->resetProperty('_ruleMessages', array()); } diff --git a/tests/Valitron/StaticVsInstanceTest.php b/tests/Valitron/StaticVsInstanceTest.php index 38a2851..1f00a23 100644 --- a/tests/Valitron/StaticVsInstanceTest.php +++ b/tests/Valitron/StaticVsInstanceTest.php @@ -17,19 +17,14 @@ class StaticVsInstanceTest extends BaseTestCase public function testRuleMessagesReplacedAfterConstructor() { $customMessage = 'custom message'; - $ruleName = 'foo'; + $ruleName = 'customRule'; + $fieldName = 'fieldName'; Validator::addRule($ruleName, function() {}, $customMessage); - - $prop = new ReflectionProperty('Valitron\Validator', '_ruleMessages'); - $prop->setAccessible(true); - $messages = $prop->getValue(); - - $this->assertEquals($customMessage, $messages[$ruleName]); - - new Validator(array(), array()); - - $messages = $prop->getValue(); - $this->assertArrayHasKey($ruleName, $messages); - $this->assertEquals($customMessage, $messages[$ruleName]); + $v = new Validator(array($fieldName => $fieldName)); + $v->rule($ruleName, $fieldName); + $v->validate(); + $messages = $v->errors(); + $this->assertArrayHasKey($fieldName, $messages); + $this->assertEquals(ucfirst("$fieldName $customMessage"), $messages[$fieldName][0]); } }