Skip to content

Commit

Permalink
Merge pull request #7 from DataValues/mismatch
Browse files Browse the repository at this point in the history
Introduce MismatchingDataValueTypeException
  • Loading branch information
JeroenDeDauw committed Apr 7, 2014
2 parents c27604f + 315bf6e commit 71b756c
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require": {
"php": ">=5.3.0",
"data-values/data-values": "~0.1",
"data-values/interfaces": "~0.1.2"
"data-values/interfaces": "~0.1.3"
},
"extra": {
"branch-alias": {
Expand Down
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;
}

}
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' )
);
}

}

0 comments on commit 71b756c

Please sign in to comment.