mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
Merge pull request #23 from neves/bug-static-lang-without-dir
Bug static lang without dir
This commit is contained in:
commit
12ebfb312f
@ -12,7 +12,7 @@
|
|||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Valitron Test Suite">
|
<testsuite name="Valitron Test Suite">
|
||||||
<directory suffix=".php">tests/Valitron</directory>
|
<directory suffix="Test.php">tests/Valitron</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@ -40,9 +40,9 @@ class Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set lang in the follow order: constructor param, static::$_lang, defaul to en
|
// 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
|
// 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::langDir($langDir);
|
||||||
static::lang($lang);
|
static::lang($lang);
|
||||||
@ -60,7 +60,7 @@ class Validator
|
|||||||
$langDir = static::langDir();
|
$langDir = static::langDir();
|
||||||
static::$_ruleMessages = require rtrim($langDir, '/') . '/' . $lang . '.php';
|
static::$_ruleMessages = require rtrim($langDir, '/') . '/' . $lang . '.php';
|
||||||
}
|
}
|
||||||
return static::$_lang;
|
return static::$_lang ?: 'en';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +71,7 @@ class Validator
|
|||||||
if($dir !== null) {
|
if($dir !== null) {
|
||||||
static::$_langDir = $dir;
|
static::$_langDir = $dir;
|
||||||
}
|
}
|
||||||
return static::$_langDir;
|
return static::$_langDir ?: dirname(dirname(__DIR__)) . '/lang';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
24
tests/Valitron/BaseTestCase.php
Normal file
24
tests/Valitron/BaseTestCase.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
class ErrorMessagesTest extends \PHPUnit_Framework_TestCase
|
class ErrorMessagesTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testErrorMessageIncludesFieldName()
|
public function testErrorMessageIncludesFieldName()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,23 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
use Valitron\Validator;
|
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()
|
protected function getLangDir()
|
||||||
{
|
{
|
||||||
return __DIR__.'/../../lang';
|
return __DIR__.'/../../lang';
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
class ValidateTest extends \PHPUnit_Framework_TestCase
|
class ValidateTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testValidWithNoRules()
|
public function testValidWithNoRules()
|
||||||
{
|
{
|
||||||
@ -16,3 +16,4 @@ if($vendorPos !== false) {
|
|||||||
$loader = require __DIR__.'/../vendor/autoload.php';
|
$loader = require __DIR__.'/../vendor/autoload.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require_once __DIR__ . '/Valitron/BaseTestCase.php';
|
||||||
Loading…
x
Reference in New Issue
Block a user