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

(-)a/Koha/Exceptions/Object.pm (+8 lines)
Lines 55-60 use Exception::Class ( Link Here
55
        description => 'Invalid data passed',
55
        description => 'Invalid data passed',
56
        fields      => ['type', 'property', 'value'],
56
        fields      => ['type', 'property', 'value'],
57
    },
57
    },
58
    'Koha::Exceptions::Object::NotInstantiated' => {
59
        isa         => 'Koha::Exceptions::Object',
60
        description => 'Tried to access a method on an uninstantiated object',
61
        fields      => ['class','method']
62
    },
58
    'Koha::Exceptions::Object::NotInStorage' => {
63
    'Koha::Exceptions::Object::NotInStorage' => {
59
        isa         => 'Koha::Exceptions::Object',
64
        isa         => 'Koha::Exceptions::Object',
60
        description => 'The object is not in storage yet',
65
        description => 'The object is not in storage yet',
Lines 76-81 sub full_message { Link Here
76
        elsif ( $self->isa('Koha::Exceptions::Object::ReadOnlyProperty') ) {
81
        elsif ( $self->isa('Koha::Exceptions::Object::ReadOnlyProperty') ) {
77
            $msg = sprintf("Invalid attempt to change readonly property: %s", $self->property );
82
            $msg = sprintf("Invalid attempt to change readonly property: %s", $self->property );
78
        }
83
        }
84
        elsif ( $self->isa('Koha::Exceptions::Object::NotInstantiated') ) {
85
            $msg = sprintf("Tried to access the '%s' method, but %s is not instantiated", $self->method, $self->class );
86
        }
79
    }
87
    }
80
88
81
    return $msg;
89
    return $msg;
(-)a/t/Koha/Exceptions.t (-2 / +23 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 6;
21
use Test::MockObject;
21
use Test::MockObject;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 176-178 subtest 'Koha::Exceptions::Patron::Relationship tests' => sub { Link Here
176
        'Exception is thrown :-D';
176
        'Exception is thrown :-D';
177
    is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
177
    is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
178
};
178
};
179
- 
179
180
subtest 'Koha::Exceptions::Object::NotInstantiated tests' => sub {
181
182
    plan tests => 5;
183
184
    use_ok('Koha::Exceptions::Object::NotInstantiated');
185
186
    throws_ok
187
        { Koha::Exceptions::Object::NotInstantiated->throw(
188
            method => 'brain_explode', class => 'Koha::JD' ); }
189
        'Koha::Exceptions::Object::NotInstantiated',
190
        'Exception is thrown :-D';
191
192
    # stringify the exception
193
    is( "$@", 'Tried to access the \'brain_explode\' method, but Koha::JD is not instantiated', 'Exception stringified correctly' );
194
195
    throws_ok
196
        { Koha::Exceptions::Object::NotInstantiated->throw( "Manual message exception" ) }
197
        'Koha::Exceptions::Object::NotInstantiated',
198
        'Exception is thrown :-D';
199
    is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
200
};

Return to bug 25423