入力値が正しいURLの文字列かを判定。URLが存在するかどうかの判定ではない。
以下の実行で、ダウンロードできます
$ git clone git@gist.github.com:09e606edbaed91e3be3b19ef9d23b21d.git tests/Unit/Validations/Url
入力値が正しいURLの文字列かを判定。URLが存在するかどうかの判定ではない。
以下の実行で、ダウンロードできます
$ git clone git@gist.github.com:09e606edbaed91e3be3b19ef9d23b21d.git tests/Unit/Validations/Url
<?php | |
namespace Tests\Unit\Validations\Url; | |
use Tests\TestCase; | |
use Validator; | |
class UrlTest extends TestCase | |
{ | |
/** | |
* @test | |
* @dataProvider provider_url | |
*/ | |
public function url($input, $expected) | |
{ | |
$v = Validator::make( | |
$input, | |
['field' => 'required|url'] | |
); | |
$this->assertEquals($expected, $v->passes()); | |
} | |
public function provider_url() | |
{ | |
return [ | |
[['field' => 'https://larajapan.com'], true], | |
[['field' => 'https://www.larajapan.com'], true], | |
[['field' => 'https://larajapan.com?foo=bar'], true], | |
[['field' => 'https://fake.larajapan.com'], true], | |
[['field' => 'larajapan.com'], false], // httpsがない | |
]; | |
} | |
} |