From d2dcf9784c321258c185e60a7a7ed9cde0f51fb1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 9 Aug 2016 16:34:15 +0100 Subject: [PATCH] [SIGNED-OFF]Bug 17091: In a first phase, restrict the usage of AUTOLOAD in Koha::Objects To make sure the methods will be covered by tests and devs won't overused this method, I think it may be a good idea to restrict its usage. Signed-off-by: Hector Castro AUTOLOAD added. No Koha QA errors. Test passed successfully --- Koha/Objects.pm | 2 ++ t/db_dependent/Koha/Objects.t | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 1ff33b3..dd8d221 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -240,9 +240,11 @@ Currently count, pager, reset and update are covered. sub AUTOLOAD { my ( $self, @params ) = @_; + my @known_methods = qw( count pager reset update ); my $method = our $AUTOLOAD; $method =~ s/.*:://; + carp "The method $method is not covered by tests" and return unless grep {/^$method$/} @known_methods; my $r = eval { $self->_resultset->$method(@params) }; if ( $@ ) { carp "No method $method found for " . ref($self) . " " . $@; diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t index d1cb9e1..8e7dc6a 100644 --- a/t/db_dependent/Koha/Objects.t +++ b/t/db_dependent/Koha/Objects.t @@ -19,7 +19,8 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; +use Test::Warn; use Koha::Authority::Types; use Koha::Cities; @@ -66,5 +67,10 @@ subtest 'reset' => sub { is( $patrons->reset->next->borrowernumber, $first_borrowernumber, 'Koha::Objects->reset should work as expected'); }; +subtest 'not_covered_yet' => sub { + plan tests => 1; + 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"; +}; + $schema->storage->txn_rollback; 1; -- 1.7.10.4