From f1ac424c6ba727323aa1f9374228090996157812 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 7 Sep 2017 09:24:28 +0200 Subject: [PATCH] Bug 15339: [QA Follow-up] Add a warning too when source is not supplied Content-Type: text/plain; charset=utf-8 When you do not supply a source and add a few wrong parameters, you would not be warned. Because build simply returns undef. Adding a carp and a test for that situation too. Note: In the earlier subtest 'trivial tests' build was called without source. This now generates a warning. We just catch if there is a warning and test the actual warning itself later on. Test plan: Run t/db_dependent/TestBuilder.t Signed-off-by: Marcel de Rooy --- t/db_dependent/TestBuilder.t | 14 +++++++++++--- t/lib/TestBuilder.pm | 6 +++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/TestBuilder.t b/t/db_dependent/TestBuilder.t index 5ef269f..c3ea95c 100644 --- a/t/db_dependent/TestBuilder.t +++ b/t/db_dependent/TestBuilder.t @@ -36,12 +36,14 @@ our $builder; subtest 'Start with some trivial tests' => sub { - plan tests => 6; + plan tests => 7; $builder = t::lib::TestBuilder->new; isnt( $builder, undef, 'We got a builder' ); - is( $builder->build, undef, 'build without arguments returns undef' ); + my $data; + warning_like { my $data = $builder->build; } qr/.+/, 'Catch a warning'; + is( $data, undef, 'build without arguments returns undef' ); is( ref( $builder->schema ), 'Koha::Schema', 'check schema' ); is( ref( $builder->can('delete') ), 'CODE', 'found delete method' ); @@ -391,7 +393,7 @@ subtest 'build_object() tests' => sub { }; subtest '->build parameter' => sub { - plan tests => 2; + plan tests => 3; # Test to make sure build() warns user of unknown parameters. warnings_are { @@ -409,6 +411,12 @@ subtest '->build parameter' => sub { branchcode => 'BRANCH_2' # This is wrong! }) } qr/unknown param/i, "Carp unknown parameters"; + + warnings_like { + $builder->build({ + zource => 'Branch', # Intentional spelling error + }) + } qr/Source parameter not specified/, "Catch warning on missing source"; }; $schema->storage->txn_rollback; diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 1b56f92..2693e9c 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -86,7 +86,11 @@ sub build { # build returns a hash of column values for a created record, or undef # build does NOT update a record, or pass back values of an existing record my ($self, $params) = @_; - my $source = $params->{source} || return; + my $source = $params->{source}; + if( !$source ) { + carp "Source parameter not specified!"; + return; + } my $value = $params->{value}; my @unknowns = grep( !/^(source|value)$/, keys %{ $params }); -- 2.1.4