Example #1
0
 public function testDnsGetRecord()
 {
     DnsMock::withMockedHosts(array('example.com' => array(array('type' => 'A', 'ip' => '1.2.3.4'), array('type' => 'PTR', 'ip' => '2.3.4.5'))));
     $records = array(array('host' => 'example.com', 'class' => 'IN', 'ttl' => 1, 'type' => 'A', 'ip' => '1.2.3.4'), $ptr = array('host' => 'example.com', 'class' => 'IN', 'ttl' => 1, 'type' => 'PTR', 'ip' => '2.3.4.5'));
     $this->assertFalse(DnsMock::dns_get_record('foobar.com'));
     $this->assertSame($records, DnsMock::dns_get_record('example.com'));
     $this->assertSame($records, DnsMock::dns_get_record('example.com', DNS_ALL));
     $this->assertSame($records, DnsMock::dns_get_record('example.com', DNS_A | DNS_PTR));
     $this->assertSame(array($ptr), DnsMock::dns_get_record('example.com', DNS_PTR));
 }
Example #2
0
 public function testIsValidCheckRecordValue()
 {
     $recordName = '_acme-challenge.bar.com.';
     $recordValue = 'record_value';
     DnsMock::register(DnsValidator::class);
     DnsMock::withMockedHosts([$recordName => [['type' => 'A', 'ip' => '1.2.3.4'], ['type' => 'TXT', 'entries' => ['somethingElse']]]]);
     $mockExtractor = $this->prophesize(DnsDataExtractor::class);
     $stubChallenge = $this->prophesize(AuthorizationChallenge::class);
     $validator = new DnsValidator($mockExtractor->reveal());
     $mockExtractor->getRecordName($stubChallenge->reveal())->willReturn($recordName);
     $mockExtractor->getRecordValue($stubChallenge->reveal())->willReturn($recordValue);
     $this->assertFalse($validator->isValid($stubChallenge->reveal()));
 }
 public function testHostnameIsProperlyParsed()
 {
     DnsMock::withMockedHosts(array('baz.com' => array(array('type' => 'MX'))));
     $this->validator->validate('"foo@bar"@baz.com', new Email(array('checkMX' => true)));
     $this->assertNoViolation();
 }
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     if ($this->expectedDeprecations) {
         restore_error_handler();
         try {
             $prefix = "@expectedDeprecation:\n  ";
             $test->assertStringMatchesFormat($prefix . implode("\n  ", $this->expectedDeprecations), $prefix . implode("\n  ", $this->gatheredDeprecations));
         } catch (\PHPUnit_Framework_AssertionFailedError $e) {
             $test->getTestResultObject()->addFailure($test, $e, $time);
         }
         $this->expectedDeprecations = $this->gatheredDeprecations = $this->previousErrorHandler = null;
     }
     if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
         $groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false));
         if (in_array('time-sensitive', $groups, true)) {
             ClockMock::withClockMock(false);
         }
         if (in_array('dns-sensitive', $groups, true)) {
             DnsMock::withMockedHosts(array());
         }
     }
 }
Example #5
0
 /**
  * @dataProvider getCheckDns
  * @requires function Symfony\Bridge\PhpUnit\DnsMock::withMockedHosts
  */
 public function testCheckDns($violation)
 {
     DnsMock::withMockedHosts(array('example.com' => array(array('type' => $violation ? '' : 'A'))));
     $constraint = new Url(array('checkDNS' => true, 'dnsMessage' => 'myMessage'));
     $this->validator->validate('http://example.com', $constraint);
     if (!$violation) {
         $this->assertNoViolation();
     } else {
         $this->buildViolation('myMessage')->setParameter('{{ value }}', '"example.com"')->setCode(Url::INVALID_URL_ERROR)->assertRaised();
     }
 }
Example #6
0
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
         $groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName());
         if (in_array('time-sensitive', $groups, true)) {
             ClockMock::withClockMock(false);
         }
         if (in_array('dns-sensitive', $groups, true)) {
             DnsMock::withMockedHosts(array());
         }
     }
 }