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

(-)a/Koha/Exceptions/Object.pm (+20 lines)
Line 0 Link Here
1
package Koha::Exceptions::Object;
2
3
use Modern::Perl;
4
5
use Exception::Class (
6
7
    'Koha::Exceptions::Object' => {
8
        description => 'Something went wrong!',
9
    },
10
    'Koha::Exceptions::Object::MethodNotFound' => {
11
        isa => 'Koha::Exceptions::Object',
12
        description => "Invalid method",
13
    },
14
    'Koha::Exceptions::Object::PropertyNotFound' => {
15
        isa => 'Koha::Exceptions::Object',
16
        description => "Invalid property",
17
    }
18
);
19
20
1;
(-)a/Koha/Object.pm (-5 / +4 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Exceptions::Object;
25
26
26
=head1 NAME
27
=head1 NAME
27
28
Lines 185-192 sub set { Link Here
185
186
186
    foreach my $p ( keys %$properties ) {
187
    foreach my $p ( keys %$properties ) {
187
        unless ( grep {/^$p$/} @columns ) {
188
        unless ( grep {/^$p$/} @columns ) {
188
            carp("No property $p!");
189
            Koha::Exceptions::Object::PropertyNotFound->throw( "No property $p for " . ref($self) );
189
            return 0;
190
        }
190
        }
191
    }
191
    }
192
192
Lines 273-282 sub AUTOLOAD { Link Here
273
            my $value = $self->_result()->get_column( $method );
273
            my $value = $self->_result()->get_column( $method );
274
            return $value;
274
            return $value;
275
        }
275
        }
276
    } else {
277
        Koha::Exceptions::Object::MethodNotFound->throw( "No method $method for " . ref($self) );
276
    }
278
    }
277
278
    carp "No method $method!";
279
    return;
280
}
279
}
281
280
282
=head3 _type
281
=head3 _type
(-)a/t/db_dependent/Koha/Objects.t (-5 / +28 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 7;
22
use Test::More tests => 8;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use Koha::Authority::Types;
25
use Koha::Authority::Types;
Lines 29-36 use Koha::Database; Link Here
29
29
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
31
32
use Try::Tiny;
33
32
my $schema = Koha::Database->new->schema;
34
my $schema = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
35
$schema->storage->txn_begin;
36
my $builder = t::lib::TestBuilder->new;
34
37
35
is( ref(Koha::Authority::Types->find('')), 'Koha::Authority::Type', 'Koha::Objects->find should work if the primary key is an empty string' );
38
is( ref(Koha::Authority::Types->find('')), 'Koha::Authority::Type', 'Koha::Objects->find should work if the primary key is an empty string' );
36
39
Lines 40-46 is( $borrowernumber_exists, 1, 'Koha::Objects->columns should return the table c Link Here
40
43
41
subtest 'update' => sub {
44
subtest 'update' => sub {
42
    plan tests => 2;
45
    plan tests => 2;
43
    my $builder = t::lib::TestBuilder->new;
46
44
    $builder->build( { source => 'City', value => { city_country => 'UK' } } );
47
    $builder->build( { source => 'City', value => { city_country => 'UK' } } );
45
    $builder->build( { source => 'City', value => { city_country => 'UK' } } );
48
    $builder->build( { source => 'City', value => { city_country => 'UK' } } );
46
    $builder->build( { source => 'City', value => { city_country => 'UK' } } );
49
    $builder->build( { source => 'City', value => { city_country => 'UK' } } );
Lines 60-66 subtest 'pager' => sub { Link Here
60
63
61
subtest 'reset' => sub {
64
subtest 'reset' => sub {
62
    plan tests => 1;
65
    plan tests => 1;
63
    my $builder   = t::lib::TestBuilder->new;
66
64
    my $patrons = Koha::Patrons->search;
67
    my $patrons = Koha::Patrons->search;
65
    my $first_borrowernumber = $patrons->next->borrowernumber;
68
    my $first_borrowernumber = $patrons->next->borrowernumber;
66
    my $second_borrowernumber = $patrons->next->borrowernumber;
69
    my $second_borrowernumber = $patrons->next->borrowernumber;
Lines 69-75 subtest 'reset' => sub { Link Here
69
72
70
subtest 'delete' => sub {
73
subtest 'delete' => sub {
71
    plan tests => 2;
74
    plan tests => 2;
72
    my $builder   = t::lib::TestBuilder->new;
75
73
    my $patron_1 = $builder->build({source => 'Borrower'});
76
    my $patron_1 = $builder->build({source => 'Borrower'});
74
    my $patron_2 = $builder->build({source => 'Borrower'});
77
    my $patron_2 = $builder->build({source => 'Borrower'});
75
    is( Koha::Patrons->search({ -or => { borrowernumber => [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber}]}})->delete, 2, '');
78
    is( Koha::Patrons->search({ -or => { borrowernumber => [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber}]}})->delete, 2, '');
Lines 81-85 subtest 'not_covered_yet' => sub { Link Here
81
    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";
84
    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";
82
};
85
};
83
86
87
subtest 'Exceptions' => sub {
88
    plan tests => 2;
89
90
    my $patron_borrowernumber = $builder->build({ source => 'Borrower' })->{ borrowernumber };
91
    my $patron = Koha::Patrons->find( $patron_borrowernumber );
92
93
    try {
94
        $patron->blah('blah');
95
    } catch {
96
        ok( $_->isa('Koha::Exceptions::Object::MethodNotFound'),
97
            'Calling a non-existent method should raise a Koha::Exceptions::Object::MethodNotFound exception' );
98
    };
99
100
    try {
101
        $patron->set({ blah => 'blah' });
102
    } catch {
103
        ok( $_->isa('Koha::Exceptions::Object::PropertyNotFound'),
104
            'Setting a non-existent property should raise a Koha::Exceptions::Object::PropertyNotFound exception' );
105
    };
106
};
107
84
$schema->storage->txn_rollback;
108
$schema->storage->txn_rollback;
85
1;
109
1;
86
- 

Return to bug 17425