Skip to content

Instantly share code, notes, and snippets.

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

バリデーション:array

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

laravel 5.5

gistの画面

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

$ git clone git@gist.github.com:a6312a0ac2cb2e24d54f0bf20d66a874.git tests/Unit/Validations/Array
<?php
namespace Tests\Unit\Validations\ArrayValidation;
use Tests\TestCase;
use Validator;
class ArrayTest extends TestCase
{
/**
* @test
* @dataProvider provider_array
*/
public function array_test($input, $expected)
{
$v = Validator::make(
$input,
['values' => 'required|array']
);
$this->assertEquals($expected, $v->passes());
}
public function provider_array()
{
return [
// 配列
[['values' => [1]], true],
[['values' => ['a','b']], true],
[['values' => []], false], // arrayでなくrequiredのため
// 文字列
[['values' => '[1]'], false],
[['values' => 'abcd'], false],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment