Beispiel #1
0
 /**
  * Returns if the given domain is available.
  *
  * @param Domain|string  $domain Domain.
  *
  * @return boolean `true` if the domain is available, `false` if not.
  *
  * @throws AvailabilityException when no pattern exists for the given TLD.
  */
 public function isAvailable($domain)
 {
     if (false === $domain instanceof Domain) {
         $domain = Domain::create($domain);
     }
     $data = $this->data->getByTld($domain->getTld());
     if (false === isset($data['patterns']['notRegistered'])) {
         throw new AvailabilityException(sprintf('No pattern exists to check availability of %s domains.', $domain->getTld()));
     }
     $this->lastWhoisResult = $this->whoisClient->query($domain);
     if (preg_match($data['patterns']['notRegistered'], $this->lastWhoisResult)) {
         return true;
     }
     return false;
 }
Beispiel #2
0
 /**
  * @test
  * @covers Cocur\Domain\Whois\Client::query()
  */
 public function queryWaitPeriod()
 {
     $domain = m::mock('Cocur\\Domain\\Domain');
     $domain->shouldReceive('getDomainName')->once()->andReturn('florianeckerstorfer.com');
     $domain->shouldReceive('getTld')->once()->andReturn('com');
     $connection = m::mock('Cocur\\Domain\\Connection\\ConnectionInterface');
     $connection->shouldReceive('open')->twice()->andReturn($connection);
     $connection->shouldReceive('write')->twice()->andReturn($connection);
     $connection->shouldReceive('read')->once()->andReturn(file_get_contents(__DIR__ . '/../fixtures/whois_period.txt'));
     $connection->shouldReceive('read')->once()->andReturn(file_get_contents(__DIR__ . '/../fixtures/whois_reg.txt'));
     $connection->shouldReceive('close')->twice();
     $this->data->shouldReceive('getByTld')->andReturn($this->comData);
     $this->factory->shouldReceive('createStreamConnection')->andReturn($connection);
     $this->assertRegExp('/Domain Name: FLORIANECKERSTORFER\\.COM/', $this->client->query($domain));
 }