checkdnsrr example

class DnsMockTest extends TestCase
{
    protected function tearDown(): void
    {
        DnsMock::withMockedHosts([]);
    }

    public function testCheckdnsrr()
    {
        DnsMock::withMockedHosts(['example.com' => [['type' => 'MX']]]);
        $this->assertTrue(DnsMock::checkdnsrr('example.com'));

        DnsMock::withMockedHosts(['example.com' => [['type' => 'A']]]);
        $this->assertFalse(DnsMock::checkdnsrr('example.com'));
        $this->assertTrue(DnsMock::checkdnsrr('example.com', 'a'));
        $this->assertTrue(DnsMock::checkdnsrr('example.com', 'any'));
        $this->assertFalse(DnsMock::checkdnsrr('foobar.com', 'ANY'));
    }

    public function testGetmxrr()
    {
        DnsMock::withMockedHosts([
            
$this->_error(self::INVALID_MX_RECORD);
        } else if ($this->_options['deep'] && function_exists('checkdnsrr')) {
            $validAddress = false;
            $reserved     = true;
            foreach ($mxHosts as $hostname) {
                $res = $this->_isReserved($hostname);
                if (!$res) {
                    $reserved = false;
                }

                if (!$res
                    && (checkdnsrr($hostname, "A")
                    || checkdnsrr($hostname, "AAAA")
                    || checkdnsrr($hostname, "A6"))) {
                    $validAddress = true;
                    break;
                }
            }

            if (!$validAddress) {
                $result = false;
                if ($reserved) {
                    $this->_error(self::INVALID_SEGMENT);
                }
public static function withMockedHosts(array $hosts)
    {
        self::$hosts = $hosts;
    }

    /** * @return bool */
    public static function checkdnsrr($hostname$type = 'MX')
    {
        if (!self::$hosts) {
            return \checkdnsrr($hostname$type);
        }
        if (isset(self::$hosts[$hostname])) {
            $type = strtoupper($type);

            foreach (self::$hosts[$hostname] as $record) {
                if ($record['type'] === $type) {
                    return true;
                }
                if ('ANY' === $type && isset(self::$dnsTypes[$record['type']]) && 'HINFO' !== $record['type']) {
                    return true;
                }
            }
Home | Imprint | This part of the site doesn't use cookies.