mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
missing language file now raises InvalidArgumentException
This commit is contained in:
parent
367ec9a7c7
commit
f793bb7555
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Valitron;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Validation Class
|
||||
*
|
||||
@ -45,7 +47,12 @@ class Validator
|
||||
$langDir = $langDir ?: static::langDir();
|
||||
|
||||
// Load language file in directory
|
||||
static::$_ruleMessages = include rtrim($langDir, '/') . '/' . $lang . '.php';
|
||||
$langFile = rtrim($langDir, '/') . '/' . $lang . '.php';
|
||||
if ( stream_resolve_include_path($langFile) ) {
|
||||
static::$_ruleMessages = include $langFile;
|
||||
} else {
|
||||
throw new InvalidArgumentException("fail to load language file '$langFile'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
use Valitron\Validator;
|
||||
|
||||
class StaticLangTest extends BaseTestCase
|
||||
class LangTest extends BaseTestCase
|
||||
{
|
||||
protected function getLangDir()
|
||||
{
|
||||
@ -41,4 +41,13 @@ class StaticLangTest extends BaseTestCase
|
||||
$validator = new Validator(array());
|
||||
$this->assertEquals(realpath($this->getLangDir()), realpath(Validator::langDir()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage fail to load language file '/this/dir/does/not/exists/en.php'
|
||||
*/
|
||||
public function testLangException()
|
||||
{
|
||||
new Validator(array(), array(), 'en', '/this/dir/does/not/exists');
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user