Skip to content

Commit

Permalink
Merge pull request #13 from utopia-php/meldiron/getregisterable-doesn-1
Browse files Browse the repository at this point in the history
Improve edge cases
  • Loading branch information
eldadfux authored Feb 2, 2022
2 parents 4740d64 + 4a7158b commit 2c83bc8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Domains/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class Domain
*/
public function __construct(string $domain)
{
if ((strpos($domain, 'http') === 0) || (strpos($domain, 'https') === 0)) {
throw new Exception('$domain must be a valid domain or hostname');
if ((strpos($domain, 'http://') === 0) || (strpos($domain, 'https://') === 0)) {
throw new Exception("'{$domain}' must be a valid domain or hostname");
}

$this->domain = \mb_strtolower($domain);
Expand Down
20 changes: 20 additions & 0 deletions tests/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ class DomainTest extends TestCase
*/
protected $test = null;

public function testEdgecaseDomains()
{
$domain = new Domain('httpmydomain.com');
$this->assertEquals('httpmydomain.com', $domain->getRegisterable());
}

public function testEdgecaseDomainsError()
{
$this->expectException('Exception');
$this->expectExceptionMessage("'http://httpmydomain.com' must be a valid domain or hostname");
$domain = new Domain('http://httpmydomain.com');
}

public function testEdgecaseDomainsError2()
{
$this->expectException('Exception');
$this->expectExceptionMessage("'https://httpmydomain.com' must be a valid domain or hostname");
$domain = new Domain('https://httpmydomain.com');
}

public function testExampleCoUk()
{
$domain = new Domain('demo.example.co.uk');
Expand Down

0 comments on commit 2c83bc8

Please sign in to comment.