入力値が正しいタイムゾーンの文字列かを判定。phpのtimezone_identifiers_list()を使用。
以下の実行で、ダウンロードできます
$ git clone git@gist.github.com:3151af45037c82b501f0b87de1f67317.git tests/Unit/Validations/Timezone
入力値が正しいタイムゾーンの文字列かを判定。phpのtimezone_identifiers_list()を使用。
以下の実行で、ダウンロードできます
$ git clone git@gist.github.com:3151af45037c82b501f0b87de1f67317.git tests/Unit/Validations/Timezone
<?php | |
namespace Tests\Unit\Validations\Timezone; | |
use Tests\TestCase; | |
use Validator; | |
class TimezoneTest extends TestCase | |
{ | |
/** | |
* @test | |
* @dataProvider provider_timezone | |
*/ | |
public function timezone($input, $expected) | |
{ | |
$v = Validator::make( | |
$input, | |
['field' => 'required|timezone'] | |
); | |
$this->assertEquals($expected, $v->passes()); | |
} | |
public function provider_timezone() | |
{ | |
return [ | |
[['field' => 'Japan'], true], | |
[['field' => 'Asia/Tokyo'], true], | |
[['field' => 'Asia/Osaka'], false], // 存在しない | |
]; | |
} | |
} |