Skip to content

Instantly share code, notes, and snippets.

@lotsofbytes
Last active October 6, 2018 19:00
Show Gist options
  • Save lotsofbytes/1abce0e432eddb2f631aab2d67a32af3 to your computer and use it in GitHub Desktop.
Save lotsofbytes/1abce0e432eddb2f631aab2d67a32af3 to your computer and use it in GitHub Desktop.
[バリデーション:string] #laravel #L55 #validation

バリデーション:string

入力値が、文字列であることを判定。

laravel 5.5

gistの画面

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

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