forked from php/web-php
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIsEmailableAddressTest.php
More file actions
73 lines (61 loc) · 1.95 KB
/
IsEmailableAddressTest.php
File metadata and controls
73 lines (61 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
namespace phpweb\Test\Unit;
use PHPUnit\Framework;
#[Framework\Attributes\CoversFunction('is_emailable_address')]
final class IsEmailableAddressTest extends Framework\TestCase
{
public static function setUpBeforeClass(): void
{
require_once __DIR__ . '/../../include/email-validation.inc';
}
#[Framework\Attributes\DataProvider('provideInvalidEmail')]
public function testIsEmailableAddressReturnsFalseWhenEmailIsInvalid(string $email): void
{
$isEmailableAddress = is_emailable_address($email);
self::assertFalse($isEmailableAddress);
}
/**
* @return \Generator<string, array{0: string}>
*/
public static function provideInvalidEmail(): \Generator
{
$values = [
'jcastagnetto-i-hate-spam@NOSPAMyahoo.test',
'jcastagnetto@NoSpam-yahoo.com',
'jmcastagnetto@chek2.com',
'wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff',
'wrong-email-address@lists.php.net',
];
foreach ($values as $value) {
yield $value => [
$value,
];
}
}
#[Framework\Attributes\DataProvider('provideValidEmail')]
public function testIsEmailableAddressReturnsTrueWhenEmailIsValid(string $email): void
{
$isEmailableAddress = is_emailable_address($email);
self::assertTrue($isEmailableAddress);
}
/**
* @return \Generator<string, array{0: string}>
*/
public static function provideValidEmail(): \Generator
{
$values = [
'asasasd324324@php.net',
'jcastagnetto-delete-this-@yahoo.com',
'jcastagnetto-NO-SPAM@yahoo.com',
'jesusmc@scripps.edu',
'jmcastagnetto@yahoo.com',
'not-exists@thephp.foundation',
];
foreach ($values as $value) {
yield $value => [
$value,
];
}
}
}