Skip to content

Instantly share code, notes, and snippets.

@lotsofbytes
Last active October 6, 2018 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotsofbytes/3151af45037c82b501f0b87de1f67317 to your computer and use it in GitHub Desktop.
Save lotsofbytes/3151af45037c82b501f0b87de1f67317 to your computer and use it in GitHub Desktop.
[バリデーション:timezone] #laravel #L55 #validation

バリデーション:timezone

入力値が正しいタイムゾーンの文字列かを判定。phpのtimezone_identifiers_list()を使用。

laravel 5.5

gistの画面

以下の実行で、ダウンロードできます

$ 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], // 存在しない
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment