入力値が、指定の正規表現のパターンにマッチすることを判定。
以下の実行で、ダウンロードできます
$ git clone git@gist.github.com:89e1823eb985fa7c7d6d07ba17de4e6c.git tests/Unit/Validations/Regex
入力値が、指定の正規表現のパターンにマッチすることを判定。
以下の実行で、ダウンロードできます
$ git clone git@gist.github.com:89e1823eb985fa7c7d6d07ba17de4e6c.git tests/Unit/Validations/Regex
<?php | |
namespace Tests\Unit\Validations\Regex; | |
use Tests\TestCase; | |
use Validator; | |
class RegexTest extends TestCase | |
{ | |
/** | |
* @test | |
* @dataProvider provider_regex | |
*/ | |
public function regex_test($input, $expected) | |
{ | |
$v = Validator::make( | |
$input, | |
['field' => 'required|regex:/^([a-z]+)$/'] | |
); | |
$this->assertEquals($expected, $v->passes()); | |
} | |
public function provider_regex() | |
{ | |
return [ | |
[['field' => 'abcd'], true], | |
[['field' => 'ABCD'], false], | |
[['field' => ' abcd'], false], | |
]; | |
} | |
} |