入力値が、配列値であることを判定。
以下の実行で、ダウンロードできます
$ git clone git@gist.github.com:a6312a0ac2cb2e24d54f0bf20d66a874.git tests/Unit/Validations/Array
入力値が、配列値であることを判定。
以下の実行で、ダウンロードできます
$ 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], | |
]; | |
} | |
} |