File: IsEmailFunctionTests.php

package info (click to toggle)
php-email-validator 4.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 760 kB
  • sloc: php: 3,534; makefile: 19; xml: 18
file content (43 lines) | stat: -rw-r--r-- 1,278 bytes parent folder | download | duplicates (3)
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
<?php

namespace Egulias\EmailValidator\Tests\EmailValidator\Validation;

use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\DNSCheckValidation;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
use PHPUnit\Framework\TestCase;

class IsEmailFunctionTests extends TestCase
{
    /**
     * @dataProvider isEmailTestSuite
     */
    public function testAgainstIsEmailTestSuite($email)
    {
        $validator = new EmailValidator();
        $validations = new MultipleValidationWithAnd([
            new NoRFCWarningsValidation(),
            new DNSCheckValidation()
        ]);

        $this->assertFalse($validator->isValid($email, $validations), "Tested email " . $email);

    }

    public function isEmailTestSuite()
    {
        $testSuite = __DIR__ . '/../../resources/is_email_tests.xml';
        $document = new \DOMDocument();
        $document->load($testSuite);
        $elements = $document->getElementsByTagName('test');
        $tests = [];

        foreach($elements as $testElement) {
            $childNode = $testElement->childNodes;
            $tests[][] = ($childNode->item(1)->getAttribute('value'));
        }

        return $tests;
    }
}