Skip to content

Commit

Permalink
Split a test into 2 and DRY up code
Browse files Browse the repository at this point in the history
I split the test into one really basic one and a more functional one.

The more functional one now has DRY-er code and is easier to add more tests to.
It also paves the way for testing IP based lookups easier in the future.
  • Loading branch information
mallardduck committed May 3, 2018
1 parent d13e1a5 commit 75085c6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 48 deletions.
63 changes: 63 additions & 0 deletions tests/WhoisLocatorLookupsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
namespace MallardDuck\Whois\Test;

use PHPUnit\Framework\TestCase;
use MallardDuck\Whois\WhoisServerList\Locator;

/**
* Corresponding Class to test the Locator class
*
* For each class in your library, there should be a corresponding Unit-Test for it
* Unit-Tests should be as much as possible independent from other test going on.
*
* @author mallardduck <[email protected]>
*/
class WhoisLocatorLookupsTest extends TestCase
{


/**
* Test the ability to call the locators find function and get function fluently.
* @param string $domain Test domains!
* @param string $server Whois Server domains!
* @dataProvider validDomainPairsProvider
*/
public function testFindAndGetCorrectDomainWhoisServer($domain, $server)
{
$var = new Locator;
$results = $var->findWhoisServer($domain)->getWhoisServer();
$this->assertTrue(is_string($results) && !empty($results));
$this->assertTrue($server === $results);
unset($var, $results);
}

/**
* Test the ability to call the locators get function directly.
* @param string $domain Test domains!
* @param string $server Whois Server domains!
* @dataProvider validDomainPairsProvider
*/
public function testGetCorrectDomainWhoisServer($domain, $server)
{
$var = new Locator;
$results = $var->getWhoisServer($domain);
$this->assertTrue(is_string($results) && !empty($results));
$this->assertTrue($server === $results);
unset($var, $results);
}

/**
* A list of valid domain and whois server domain pairs.
*/
public function validDomainPairsProvider()
{
return [
['google.com', 'whois.verisign-grs.com'],
['google.net', 'whois.verisign-grs.com'],
['liquidweb.com', 'whois.verisign-grs.com'],
['danpock.xyz', 'whois.nic.xyz'],
['bbc.co.uk', 'whois.nic.uk'],
['goober.biz', 'whois.biz'], // literally a made up domain - but it does exist lul
];
}
}
48 changes: 0 additions & 48 deletions tests/WhoisLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,52 +52,4 @@ public function testFindWhoisServer()
$this->assertTrue(is_array($match) && !empty($match) && count($match) >= 1);
unset($var, $match);
}

/**
* Test function comment stub.
*/
public function testFindServerThenGetWhoisServer()
{
$var = new Locator;
$results = $var->findWhoisServer("com.com")->getWhoisServer();
$this->assertTrue(is_string($results) && !empty($results));
$this->assertTrue("whois.verisign-grs.com" === $results);
unset($var, $results);

$var = new Locator;
$results = $var->findWhoisServer("google.com")->getWhoisServer();
$this->assertTrue(is_string($results) && !empty($results));
$this->assertTrue("whois.verisign-grs.com" === $results);
unset($var, $results);

$var = new Locator;
$results = $var->findWhoisServer("danpock.xyz")->getWhoisServer();
$this->assertTrue(is_string($results) && !empty($results));
$this->assertTrue("whois.nic.xyz" === $results);
unset($var, $results);
}

/**
* Test function comment stub.
*/
public function testGetWhoisServerDirect()
{
$var = new Locator;
$results = $var->getWhoisServer("com.com");
$this->assertTrue(is_string($results) && !empty($results));
$this->assertTrue("whois.verisign-grs.com" === $results);
unset($var, $results);

$var = new Locator;
$results = $var->getWhoisServer("google.com");
$this->assertTrue(is_string($results) && !empty($results));
$this->assertTrue("whois.verisign-grs.com" === $results);
unset($var, $results);

$var = new Locator;
$results = $var->getWhoisServer("danpock.xyz");
$this->assertTrue(is_string($results) && !empty($results));
$this->assertTrue("whois.nic.xyz" === $results);
unset($var, $results);
}
}

0 comments on commit 75085c6

Please sign in to comment.