View | Details | Raw Unified | Return to bug 22051
Collapse All | Expand All

(-)a/Koha/Exceptions/Object.pm (+12 lines)
Lines 45-50 use Exception::Class ( Link Here
45
        isa => 'Koha::Exceptions::Object',
45
        isa => 'Koha::Exceptions::Object',
46
        description => "Method not covered by tests",
46
        description => "Method not covered by tests",
47
    },
47
    },
48
    'Koha::Exceptions::Object::BadValue' => {
49
        isa         => 'Koha::Exceptions::Object',
50
        description => 'Invalid data passed',
51
        fields      => ['type', 'property', 'value'],
52
    },
48
);
53
);
49
54
50
sub full_message {
55
sub full_message {
Lines 56-61 sub full_message { Link Here
56
        if ( $self->isa('Koha::Exceptions::Object::FKConstraint') ) {
61
        if ( $self->isa('Koha::Exceptions::Object::FKConstraint') ) {
57
            $msg = sprintf("Invalid parameter passed, %s=%s does not exist", $self->broken_fk, $self->value );
62
            $msg = sprintf("Invalid parameter passed, %s=%s does not exist", $self->broken_fk, $self->value );
58
        }
63
        }
64
        elsif ( $self->isa('Koha::Exceptions::Object::BadValue') ) {
65
            $msg = sprintf("Invalid value passed, %s=%s expected type is %s", $self->property, $self->value, $self->type );
66
        }
59
    }
67
    }
60
68
61
    return $msg;
69
    return $msg;
Lines 91-96 Exception to be used when an invalid object property has been requested. Link Here
91
99
92
Exception to be used when the invoked method is not covered by tests.
100
Exception to be used when the invoked method is not covered by tests.
93
101
102
=head2 Koha::Exceptions::Object::BadValue
103
104
Exception to be used when a bad value has been passed for a property.
105
94
=head1 Class methods
106
=head1 Class methods
95
107
96
=head2 full_message
108
=head2 full_message
(-)a/t/Koha/Exceptions.t (-2 / +20 lines)
Lines 22-28 use Test::Exception; Link Here
22
22
23
subtest 'Koha::Exceptions::Object::FKConstraint tests' => sub {
23
subtest 'Koha::Exceptions::Object::FKConstraint tests' => sub {
24
24
25
    plan tests => 5;
25
    plan tests => 9;
26
26
27
    use_ok('Koha::Exceptions::Object');
27
    use_ok('Koha::Exceptions::Object');
28
28
Lines 39-44 subtest 'Koha::Exceptions::Object::FKConstraint tests' => sub { Link Here
39
        'Koha::Exceptions::Object::FKConstraint',
39
        'Koha::Exceptions::Object::FKConstraint',
40
        'Exception is thrown :-D';
40
        'Exception is thrown :-D';
41
    is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
41
    is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
42
43
    throws_ok {
44
        Koha::Exceptions::Object::BadValue->throw(
45
            type     => 'datetime',
46
            property => 'a_property',
47
            value    => 'a_value'
48
        );
49
    }
50
    'Koha::Exceptions::Object::BadValue',
51
        'Koha::Exceptions::Object::BadValue exception is thrown :-D';
52
53
    # stringify the exception
54
    is( "$@", 'Invalid value passed, a_property=a_value expected type is datetime', 'Koha::Exceptions::Object::BadValue stringified correctly' );
55
56
    throws_ok
57
        { Koha::Exceptions::Object::BadValue->throw( "Manual message exception" ) }
58
        'Koha::Exceptions::Object::BadValue',
59
        'Koha::Exceptions::Object::BadValue is thrown :-D';
60
    is( "$@", 'Manual message exception', 'Koha::Exceptions::Object::BadValue not stringified if manually passed' );
42
};
61
};
43
62
44
subtest 'Koha::Exceptions::Password tests' => sub {
63
subtest 'Koha::Exceptions::Password tests' => sub {
45
- 

Return to bug 22051