Skip to content

Commit 7d759c8

Browse files
committed
Create ValidCountryTest.php
1 parent a0afb2d commit 7d759c8

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/Rules/ValidCountryTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Milwad\LaravelValidate\Tests\Rules;
4+
5+
use Milwad\LaravelValidate\Rules\ValidCountry;
6+
use Milwad\LaravelValidate\Tests\TestCase;
7+
8+
class ValidCountryTest extends TestCase
9+
{
10+
/**
11+
* Test country is valid by values.
12+
*/
13+
public function test_country_is_valid_by_values()
14+
{
15+
$rules = ['country' => [new ValidCountry]];
16+
17+
foreach (config('laravel-validate.countries', []) as $country) {
18+
$data = ['country' => $country];
19+
$passes = $this->app['validator']->make($data, $rules)->passes();
20+
$this->assertTrue($passes);
21+
}
22+
}
23+
24+
/**
25+
* Test country is valid by keys.
26+
*/
27+
public function test_country_is_valid_by_keys()
28+
{
29+
$rules = ['country' => [new ValidCountry(true)]];
30+
31+
foreach (array_keys(config('laravel-validate.countries', [])) as $country) {
32+
$data = ['country' => $country];
33+
$passes = $this->app['validator']->make($data, $rules)->passes();
34+
$this->assertTrue($passes);
35+
}
36+
}
37+
38+
/**
39+
* Test country is not valid.
40+
*/
41+
public function test_country_is_not_valid()
42+
{
43+
$rules = ['country' => [new ValidCountry]];
44+
$data = ['country' => 'Unknown'];
45+
$passes = $this->app['validator']->make($data, $rules)->passes();
46+
47+
$this->assertFalse($passes);
48+
}
49+
}

0 commit comments

Comments
 (0)