Skip to content

Instantly share code, notes, and snippets.

@lotsofbytes
Last active October 6, 2018 18:57
Show Gist options
  • Save lotsofbytes/143aa1d9512c361cb0ae5907249e3544 to your computer and use it in GitHub Desktop.
Save lotsofbytes/143aa1d9512c361cb0ae5907249e3544 to your computer and use it in GitHub Desktop.
[バリデーション:boolean] #laravel #L55 #validation

バリデーション:boolean

入力値が、ブーリアン値であることを判定。

laravel 5.5

gistの画面

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

$ git clone git@gist.github.com:143aa1d9512c361cb0ae5907249e3544.git tests/Unit/Validations/Boolean
<?php
namespace Tests\Unit\Validations\Boolean;
use Tests\TestCase;
use Validator;
class BooleanTest extends TestCase
{
/**
* @test
* @dataProvider provider_boolean
*/
public function boolean($input, $expected)
{
$v = Validator::make(
$input,
['flag' => 'required|boolean']
);
$this->assertEquals($expected, $v->passes());
}
public function provider_boolean()
{
return [
// 文字列
[['flag' => '1'], true],
[['flag' => '0'], true],
[['flag' => 'true'], false],
[['flag' => 'false'], false],
// 文字列でない
[['flag' => 1], true],
[['flag' => 0], true],
[['flag' => true], true],
[['flag' => false], true],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment