From 611f2648851b3bf2e3f47c5a89f69208be7af0c9 Mon Sep 17 00:00:00 2001 From: Marcos Neves Date: Fri, 16 Aug 2013 22:34:44 -0300 Subject: [PATCH 1/2] Add a BaseTest class to reset static properties on setUp and tearDown --- phpunit.xml | 2 +- tests/Valitron/BaseTestCase.php | 24 +++++++++++++++++++ tests/Valitron/ErrorMessages.php | 2 +- tests/Valitron/StaticLangTest.php | 17 +------------ .../{Validate.php => ValidateTest.php} | 2 +- tests/bootstrap.php | 1 + 6 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 tests/Valitron/BaseTestCase.php rename tests/Valitron/{Validate.php => ValidateTest.php} (99%) diff --git a/phpunit.xml b/phpunit.xml index 8e425f9..5693a09 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -12,7 +12,7 @@ > - tests/Valitron + tests/Valitron diff --git a/tests/Valitron/BaseTestCase.php b/tests/Valitron/BaseTestCase.php new file mode 100644 index 0000000..0dec6c4 --- /dev/null +++ b/tests/Valitron/BaseTestCase.php @@ -0,0 +1,24 @@ +tearDown(); + } + + public function tearDown() + { + $this->resetProperty('_lang'); + $this->resetProperty('_langDir'); + $this->resetProperty('_ruleMessages', array()); + } + + protected function resetProperty($name, $value = null) + { + $prop = new ReflectionProperty('Valitron\Validator', $name); + $prop->setAccessible(true); + $prop->setValue($value); + $prop->setAccessible(false); + } +} diff --git a/tests/Valitron/ErrorMessages.php b/tests/Valitron/ErrorMessages.php index b517e2f..51f7f19 100644 --- a/tests/Valitron/ErrorMessages.php +++ b/tests/Valitron/ErrorMessages.php @@ -1,7 +1,7 @@ resetProperty('_lang'); - $this->resetProperty('_langDir'); - $this->resetProperty('_ruleMessages', array()); - } - - protected function resetProperty($name, $value = null) - { - $prop = new ReflectionProperty('Valitron\Validator', $name); - $prop->setAccessible(true); - $prop->setValue($value); - $prop->setAccessible(false); - } - protected function getLangDir() { return __DIR__.'/../../lang'; diff --git a/tests/Valitron/Validate.php b/tests/Valitron/ValidateTest.php similarity index 99% rename from tests/Valitron/Validate.php rename to tests/Valitron/ValidateTest.php index 8f61764..b3d5d1b 100644 --- a/tests/Valitron/Validate.php +++ b/tests/Valitron/ValidateTest.php @@ -1,7 +1,7 @@ Date: Fri, 16 Aug 2013 23:05:24 -0300 Subject: [PATCH 2/2] fix lang and langDir to have default values --- src/Valitron/Validator.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index 6879524..cb7cc8e 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -40,9 +40,9 @@ class Validator } // set lang in the follow order: constructor param, static::$_lang, defaul to en - $lang = $lang ?: static::$_lang ?: 'en'; + $lang = $lang ?: static::lang(); // set langDir in the follow order: constructor param, static::$_langDir, default to package lang dir - $langDir = $langDir ?: static::$_langDir ?: dirname(dirname(__DIR__)) . '/lang'; + $langDir = $langDir ?: static::langDir(); static::langDir($langDir); static::lang($lang); @@ -60,7 +60,7 @@ class Validator $langDir = static::langDir(); static::$_ruleMessages = require rtrim($langDir, '/') . '/' . $lang . '.php'; } - return static::$_lang; + return static::$_lang ?: 'en'; } /** @@ -71,7 +71,7 @@ class Validator if($dir !== null) { static::$_langDir = $dir; } - return static::$_langDir; + return static::$_langDir ?: dirname(dirname(__DIR__)) . '/lang'; } /**