isa => 'Koha::Exceptions::Object',
description => "Method not covered by tests",
},
+ 'Koha::Exceptions::Object::BadValue' => {
+ isa => 'Koha::Exceptions::Object',
+ description => 'Invalid data passed',
+ fields => ['type', 'property', 'value'],
+ },
);
sub full_message {
if ( $self->isa('Koha::Exceptions::Object::FKConstraint') ) {
$msg = sprintf("Invalid parameter passed, %s=%s does not exist", $self->broken_fk, $self->value );
}
+ elsif ( $self->isa('Koha::Exceptions::Object::BadValue') ) {
+ $msg = sprintf("Invalid value passed, %s=%s expected type is %s", $self->property, $self->value, $self->type );
+ }
}
return $msg;
Exception to be used when the invoked method is not covered by tests.
+=head2 Koha::Exceptions::Object::BadValue
+
+Exception to be used when a bad value has been passed for a property.
+
=head1 Class methods
=head2 full_message
subtest 'Koha::Exceptions::Object::FKConstraint tests' => sub {
- plan tests => 5;
+ plan tests => 9;
use_ok('Koha::Exceptions::Object');
'Koha::Exceptions::Object::FKConstraint',
'Exception is thrown :-D';
is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
+
+ throws_ok {
+ Koha::Exceptions::Object::BadValue->throw(
+ type => 'datetime',
+ property => 'a_property',
+ value => 'a_value'
+ );
+ }
+ 'Koha::Exceptions::Object::BadValue',
+ 'Koha::Exceptions::Object::BadValue exception is thrown :-D';
+
+ # stringify the exception
+ is( "$@", 'Invalid value passed, a_property=a_value expected type is datetime', 'Koha::Exceptions::Object::BadValue stringified correctly' );
+
+ throws_ok
+ { Koha::Exceptions::Object::BadValue->throw( "Manual message exception" ) }
+ 'Koha::Exceptions::Object::BadValue',
+ 'Koha::Exceptions::Object::BadValue is thrown :-D';
+ is( "$@", 'Manual message exception', 'Koha::Exceptions::Object::BadValue not stringified if manually passed' );
};
subtest 'Koha::Exceptions::Password tests' => sub {