Skip to content
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

Merged
merged 5 commits into from
Apr 7, 2014
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
57 changes: 57 additions & 0 deletions src/ValueFormatters/Exceptions/DataValueTypeMismatchException.php
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 {
Copy link
Member

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


/**
* @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 "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like DataValueType is a class.

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MismatchingException? MismatchingDataValueException? BadDataValueTypeException as daniel suggests? or what?

Copy link
Member

Choose a reason for hiding this comment

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

}