Merge pull request #23 from neves/bug-static-lang-without-dir

Bug static lang without dir
This commit is contained in:
Vance Lucas 2013-08-19 06:53:03 -07:00
commit 12ebfb312f
7 changed files with 33 additions and 23 deletions

View File

@ -12,7 +12,7 @@
>
<testsuites>
<testsuite name="Valitron Test Suite">
<directory suffix=".php">tests/Valitron</directory>
<directory suffix="Test.php">tests/Valitron</directory>
</testsuite>
</testsuites>
</phpunit>

View File

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

View File

@ -0,0 +1,24 @@
<?php
class BaseTestCase extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->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);
}
}

View File

@ -1,7 +1,7 @@
<?php
use Valitron\Validator;
class ErrorMessagesTest extends \PHPUnit_Framework_TestCase
class ErrorMessagesTest extends BaseTestCase
{
public function testErrorMessageIncludesFieldName()
{

View File

@ -1,23 +1,8 @@
<?php
use Valitron\Validator;
class StaticLangTest extends \PHPUnit_Framework_TestCase
class StaticLangTest extends BaseTestCase
{
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);
}
protected function getLangDir()
{
return __DIR__.'/../../lang';

View File

@ -1,7 +1,7 @@
<?php
use Valitron\Validator;
class ValidateTest extends \PHPUnit_Framework_TestCase
class ValidateTest extends BaseTestCase
{
public function testValidWithNoRules()
{

View File

@ -16,3 +16,4 @@ if($vendorPos !== false) {
$loader = require __DIR__.'/../vendor/autoload.php';
}
require_once __DIR__ . '/Valitron/BaseTestCase.php';