-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce MismatchingDataValueTypeException #7
Changes from 4 commits
e9d309b
3a95e47
7b78d26
6d5b477
315bf6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace ValueFormatters\Exceptions; | ||
|
||
use ValueFormatters\FormattingException; | ||
|
||
/** | ||
* @since 0.2.1 | ||
* | ||
* @licence GNU GPL v2+ | ||
* @author Katie Filbert < aude.wiki@gmail.com > | ||
*/ | ||
class DataValueTypeMismatchException extends FormattingException { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $expectedValueType; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $dataValueType; | ||
|
||
/** | ||
* @param string $expectedValueType | ||
* @param string $dataValueType | ||
* @param string $message | ||
* @param \Exception $previous | ||
*/ | ||
public function __construct( $expectedValueType, $dataValueType, $message = '', | ||
\Exception $previous = null | ||
) { | ||
$this->expectedValueType = $expectedValueType; | ||
$this->dataValueType = $dataValueType; | ||
|
||
$message = "DataValueType $dataValueType does not match expected value " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like DataValueType is a class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. I'd just drop the DataValueType type part, not like repeating that is helping clarity anyway There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MismatchingException? MismatchingDataValueException? BadDataValueTypeException as daniel suggests? or what? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you are misplacing some of your comments... |
||
. "type $expectedValueType: " . $message; | ||
|
||
parent::__construct( $message, 0, $previous ); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getExpectedValueType() { | ||
return $this->expectedValueType; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDataValueType() { | ||
return $this->dataValueType; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace ValueFormatters\Tests\Exceptions; | ||
|
||
use ValueFormatters\Exceptions\DataValueTypeMismatchException; | ||
|
||
/** | ||
* @covers ValueFormatters\Exceptions\DataValueTypeMismatchException | ||
* | ||
* @group ValueFormatters | ||
* @group DataValueExtensions | ||
* | ||
* @licence GNU GPL v2+ | ||
* @author Katie Filbert < aude.wiki@gmail.com > | ||
*/ | ||
class DataValueTypeMismatchExceptionTest extends \PHPUnit_Framework_TestCase { | ||
|
||
/** | ||
* @dataProvider constructorProvider | ||
*/ | ||
public function testConstructorWithRequiredArguments( $expectedType, $actualType ) { | ||
$exception = new DataValueTypeMismatchException( $expectedType, $actualType ); | ||
|
||
$this->assertEquals( $actualType, $exception->getDataValueType() ); | ||
$this->assertEquals( $expectedType, $exception->getExpectedValueType() ); | ||
} | ||
|
||
/** | ||
* @dataProvider constructorProvider | ||
*/ | ||
public function testConstructorWithAllArguments( $expectedType, $actualType ) { | ||
$message = 'Onoez! an error!'; | ||
$previous = new \Exception( 'Onoez!' ); | ||
|
||
$exception = new DataValueTypeMismatchException( | ||
$expectedType, | ||
$actualType, | ||
$message, | ||
$previous | ||
); | ||
|
||
$this->assertEquals( $actualType, $exception->getDataValueType() ); | ||
$this->assertEquals( $expectedType, $exception->getExpectedValueType() ); | ||
$this->assertContains( $message, $exception->getMessage() ); | ||
$this->assertEquals( $previous, $exception->getPrevious() ); | ||
} | ||
|
||
public function constructorProvider() { | ||
return array( | ||
array( 'string', 'time' ), | ||
array( 'globecoordinate', 'string' ) | ||
); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MismatchingDataValueTypeException? The current one is in the format of ArgumentInvalidException, which is odd