Skip to content

Commit e7b7241

Browse files
committed
Add Exception interface, class, and test.
1 parent 0d8169e commit e7b7241

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

src/Pdp/Exception/PdpException.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/**
4+
* PHP Domain Parser: Public Suffix List based URL parsing.
5+
*
6+
* @link http://github.com/jeremykendall/php-domain-parser for the canonical source repository
7+
*
8+
* @copyright Copyright (c) 2014 Jeremy Kendall (http://about.me/jeremykendall)
9+
* @license http://github.com/jeremykendall/php-domain-parser/blob/master/LICENSE MIT License
10+
*/
11+
namespace Pdp\Exception;
12+
13+
interface PdpException
14+
{
15+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* PHP Domain Parser: Public Suffix List based URL parsing.
5+
*
6+
* @link http://github.com/jeremykendall/php-domain-parser for the canonical source repository
7+
*
8+
* @copyright Copyright (c) 2014 Jeremy Kendall (http://about.me/jeremykendall)
9+
* @license http://github.com/jeremykendall/php-domain-parser/blob/master/LICENSE MIT License
10+
*/
11+
namespace Pdp\Exception;
12+
13+
/**
14+
* Should be thrown when pdp_parse_url() return false.
15+
*
16+
* Exception name based on the PHP documentation: "On seriously malformed URLs,
17+
* parse_url() may return FALSE."
18+
*
19+
* @see http://php.net/parse_url
20+
*/
21+
class SeriouslyMalformedUrlException extends \InvalidArgumentException implements PdpException
22+
{
23+
/**
24+
* Public constructor
25+
*
26+
* @param string $malformedUrl URL that caused pdp_parse_url() to return false
27+
* @param int $code The Exception code
28+
* @param \Exception $previous The previous exception used for the exception chaining
29+
*/
30+
public function __construct($malformedUrl = "", $code = 0, $previous = null)
31+
{
32+
$message = sprintf('"%s" is one seriously malformed url.', $malformedUrl);
33+
parent::__construct($message, $code, $previous);
34+
}
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Pdp\Exception;
4+
5+
class SeriouslyMalformedUrlExceptionTest extends \PHPUnit_Framework_TestCase
6+
{
7+
public function testInstanceOfPdpException()
8+
{
9+
$this->assertInstanceOf(
10+
'Pdp\Exception\PdpException',
11+
new SeriouslyMalformedUrlException()
12+
);
13+
}
14+
15+
public function testInstanceOfInvalidArgumentException()
16+
{
17+
$this->assertInstanceOf(
18+
'InvalidArgumentException',
19+
new SeriouslyMalformedUrlException()
20+
);
21+
}
22+
23+
public function testMessage()
24+
{
25+
$url = 'http:///example.com';
26+
$this->setExpectedException(
27+
'Pdp\Exception\SeriouslyMalformedUrlException',
28+
sprintf('"%s" is one seriously malformed url.', $url)
29+
);
30+
31+
throw new SeriouslyMalformedUrlException($url);
32+
}
33+
}

0 commit comments

Comments
 (0)