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/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'; } /** 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 @@