-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from DataValues/mismatch
Introduce MismatchingDataValueTypeException
- Loading branch information
Showing
3 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 MismatchingDataValueTypeException 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 $expectedValueType "' | ||
. $expectedValueType . '": $message'; | ||
|
||
parent::__construct( $message, 0, $previous ); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getExpectedValueType() { | ||
return $this->expectedValueType; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDataValueType() { | ||
return $this->dataValueType; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
tests/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace ValueFormatters\Tests\Exceptions; | ||
|
||
use ValueFormatters\Exceptions\MismatchingDataValueTypeException; | ||
|
||
/** | ||
* @covers ValueFormatters\Exceptions\MismatchingDataValueTypeException | ||
* | ||
* @group ValueFormatters | ||
* @group DataValueExtensions | ||
* | ||
* @licence GNU GPL v2+ | ||
* @author Katie Filbert < aude.wiki@gmail.com > | ||
*/ | ||
class MismatchingDataValueTypeExceptionTest extends \PHPUnit_Framework_TestCase { | ||
|
||
/** | ||
* @dataProvider constructorProvider | ||
*/ | ||
public function testConstructorWithRequiredArguments( $expectedType, $actualType ) { | ||
$exception = new MismatchingDataValueTypeException( $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 MismatchingDataValueTypeException( | ||
$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' ) | ||
); | ||
} | ||
|
||
} |