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