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

(-)a/Koha/Object.pm (-1 / +5 lines)
Lines 392-398 sub AUTOLOAD { Link Here
392
392
393
    my @known_methods = qw( is_changed id in_storage get_column discard_changes update related_resultset make_column_dirty );
393
    my @known_methods = qw( is_changed id in_storage get_column discard_changes update related_resultset make_column_dirty );
394
394
395
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods;
395
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw(
396
        error      => sprintf("The method %s->%s is not covered by tests!", ref($self), $method),
397
        show_trace => 1
398
    ) unless grep { /^$method$/ } @known_methods;
399
396
400
397
    my $r = eval { $self->_result->$method(@_) };
401
    my $r = eval { $self->_result->$method(@_) };
398
    if ( $@ ) {
402
    if ( $@ ) {
(-)a/Koha/Objects.pm (-1 / +9 lines)
Lines 383-389 sub AUTOLOAD { Link Here
383
    my $method = our $AUTOLOAD;
383
    my $method = our $AUTOLOAD;
384
    $method =~ s/.*:://;
384
    $method =~ s/.*:://;
385
385
386
    carp "The method $method is not covered by tests" and return unless grep {/^$method$/} @known_methods;
386
387
    unless ( grep { /^$method$/ } @known_methods ) {
388
        my $class = ref($self) ? ref($self) : $self;
389
        Koha::Exceptions::Object::MethodNotCoveredByTests->throw(
390
            error      => sprintf("The method %s->%s is not covered by tests!", $class, $method),
391
            show_trace => 1
392
        );
393
    }
394
387
    my $r = eval { $self->_resultset->$method(@params) };
395
    my $r = eval { $self->_resultset->$method(@params) };
388
    if ( $@ ) {
396
    if ( $@ ) {
389
        carp "No method $method found for " . ref($self) . " " . $@;
397
        carp "No method $method found for " . ref($self) . " " . $@;
(-)a/t/db_dependent/Koha/Objects.t (-7 / +21 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 15;
22
use Test::More tests => 14;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 95-104 subtest 'delete' => sub { Link Here
95
    is( Koha::Patrons->search({ -or => { borrowernumber => [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber}]}})->count, 0, '');
95
    is( Koha::Patrons->search({ -or => { borrowernumber => [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber}]}})->count, 0, '');
96
};
96
};
97
97
98
subtest 'not_covered_yet' => sub {
99
    plan tests => 1;
100
    warning_is { Koha::Patrons->search->not_covered_yet } { carped => 'The method not_covered_yet is not covered by tests' }, "If a method is not covered by tests, the AUTOLOAD method won't execute the method";
101
};
102
subtest 'new' => sub {
98
subtest 'new' => sub {
103
    plan tests => 2;
99
    plan tests => 2;
104
    my $a_cat_code = 'A_CAT_CODE';
100
    my $a_cat_code = 'A_CAT_CODE';
Lines 188-203 subtest 'get_column' => sub { Link Here
188
};
184
};
189
185
190
subtest 'Exceptions' => sub {
186
subtest 'Exceptions' => sub {
191
    plan tests => 2;
187
    plan tests => 7;
192
188
193
    my $patron_borrowernumber = $builder->build({ source => 'Borrower' })->{ borrowernumber };
189
    my $patron_borrowernumber = $builder->build({ source => 'Borrower' })->{ borrowernumber };
194
    my $patron = Koha::Patrons->find( $patron_borrowernumber );
190
    my $patron = Koha::Patrons->find( $patron_borrowernumber );
195
191
192
    # Koha::Object
196
    try {
193
    try {
197
        $patron->blah('blah');
194
        $patron->blah('blah');
198
    } catch {
195
    } catch {
199
        ok( $_->isa('Koha::Exceptions::Object::MethodNotCoveredByTests'),
196
        ok( $_->isa('Koha::Exceptions::Object::MethodNotCoveredByTests'),
200
            'Calling a non-covered method should raise a Koha::Exceptions::Object::MethodNotCoveredByTests exception' );
197
            'Calling a non-covered method should raise a Koha::Exceptions::Object::MethodNotCoveredByTests exception' );
198
        is( $_->message, 'The method Koha::Patron->blah is not covered by tests!', 'The message raised should contain the package and the method' );
201
    };
199
    };
202
200
203
    try {
201
    try {
Lines 206-211 subtest 'Exceptions' => sub { Link Here
206
        ok( $_->isa('Koha::Exceptions::Object::PropertyNotFound'),
204
        ok( $_->isa('Koha::Exceptions::Object::PropertyNotFound'),
207
            'Setting a non-existent property should raise a Koha::Exceptions::Object::PropertyNotFound exception' );
205
            'Setting a non-existent property should raise a Koha::Exceptions::Object::PropertyNotFound exception' );
208
    };
206
    };
207
208
    # Koha::Objects
209
    try {
210
        Koha::Patrons->search->not_covered_yet;
211
    } catch {
212
        ok( $_->isa('Koha::Exceptions::Object::MethodNotCoveredByTests'),
213
            'Calling a non-covered method should raise a Koha::Exceptions::Object::MethodNotCoveredByTests exception' );
214
        is( $_->message, 'The method Koha::Patrons->not_covered_yet is not covered by tests!', 'The message raised should contain the package and the method' );
215
    };
216
217
    try {
218
        Koha::Patrons->not_covered_yet;
219
    } catch {
220
        ok( $_->isa('Koha::Exceptions::Object::MethodNotCoveredByTests'),
221
            'Calling a non-covered method should raise a Koha::Exceptions::Object::MethodNotCoveredByTests exception' );
222
        is( $_->message, 'The method Koha::Patrons->not_covered_yet is not covered by tests!', 'The message raised should contain the package and the method' );
223
    };
209
};
224
};
210
225
211
$schema->storage->txn_rollback;
226
$schema->storage->txn_rollback;
212
- 

Return to bug 20767