mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-26 18:25:09 +01:00
90 lines
2.2 KiB
PHP
90 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Rules;
|
|
|
|
use App\Rules\IsValidEmailList;
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* IsValidEmailListTest test class
|
|
*/
|
|
#[CoversClass(IsValidEmailList::class)]
|
|
class IsValidEmailListTest extends TestCase
|
|
{
|
|
use WithoutMiddleware;
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
#[DataProvider('provideValidData')]
|
|
public function test_valid_data(array $data) : void
|
|
{
|
|
$validator = Validator::make($data, ['value' => [new IsValidEmailList]]);
|
|
|
|
$this->assertFalse($validator->fails());
|
|
}
|
|
|
|
/**
|
|
* Provide Valid data for validation test
|
|
*/
|
|
public static function provideValidData() : array
|
|
{
|
|
return [
|
|
[[
|
|
'value' => 'johndoe@example.com',
|
|
]],
|
|
[[
|
|
'value' => 'johndoe@example.com|janedoe@example.com',
|
|
]],
|
|
[[
|
|
'value' => '|johndoe@example.com|janedoe@example.com',
|
|
]],
|
|
[[
|
|
'value' => 'johndoe@example.com|janedoe@example.com|',
|
|
]],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
#[DataProvider('provideInvalidData')]
|
|
public function test_invalid_data(array $data) : void
|
|
{
|
|
$validator = Validator::make($data, ['value' => [new IsValidEmailList]]);
|
|
|
|
$this->assertTrue($validator->fails());
|
|
}
|
|
|
|
/**
|
|
* Provide Valid data for validation test
|
|
*/
|
|
public static function provideInvalidData() : array
|
|
{
|
|
return [
|
|
[[
|
|
'value' => 'johndoeexamplecom',
|
|
]],
|
|
[[
|
|
'value' => 'johndoe@example.com|janedoeexamplecom',
|
|
]],
|
|
[[
|
|
'value' => 'johndoe@example.com,janedoe@example.com',
|
|
]],
|
|
[[
|
|
'value' => 'johndoe@example.com;janedoe@example.com|',
|
|
]],
|
|
[[
|
|
'value' => 'johndoe@example.com janedoe@example.com',
|
|
]],
|
|
[[
|
|
'value' => 'johndoe@example.com | janedoe@example.com',
|
|
]],
|
|
];
|
|
}
|
|
}
|