HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/be.naniguide.com/tests/Unit/DomainExtractionFromEmailTest.php
<?php

test('email domain extraction', function () {
    $cases = [
        '[email protected]'           => 'example.com',
        'Alice <[email protected]>'  => 'example2.com',
        ' [email protected] '       => 'sub.domain.org',
        'user@[127.0.0.1]'            => '[127.0.0.1]',
        'user@[IPv6:2001:db8::1]'     => '[IPv6:2001:db8::1]',
        '"John Doe" <user@例え.テスト>' => '例え.テスト',
        'multi@[email protected]'    => 'host.example',
        'no-at-symbol'                => null,
        ''                            => null,
        '<[email protected]>'      => 'nested.example',
    ];

    foreach ($cases as $email => $expected) {
        expect(\App\Library\StringHelper::getDomainFromEmail($email))
            ->toBe($expected, "Failed asserting domain extraction for: " . var_export($email, true));
    }
});