From 676e80dd8ee6b61a1f2c0d29190e0d153aaf5887 Mon Sep 17 00:00:00 2001 From: Marcos Neves Date: Tue, 20 Aug 2013 21:25:14 -0300 Subject: [PATCH] add failing tests before fix addRule --- tests/Valitron/StaticVsInstanceTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/Valitron/StaticVsInstanceTest.php b/tests/Valitron/StaticVsInstanceTest.php index c83dad4..38a2851 100644 --- a/tests/Valitron/StaticVsInstanceTest.php +++ b/tests/Valitron/StaticVsInstanceTest.php @@ -10,4 +10,26 @@ class StaticVsInstanceTest extends BaseTestCase $this->assertEquals('ar', Validator::lang(), 'instance defined lang should not replace static global lang'); } + + /** + * Rules messages added with Validator::addRule are replaced after creating validator instance + */ + public function testRuleMessagesReplacedAfterConstructor() + { + $customMessage = 'custom message'; + $ruleName = 'foo'; + 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]); + } }