Bug 15339: [QA Follow-up] Add a warning too when source is not supplied

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 <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Marcel de Rooy 2017-09-07 09:24:28 +02:00 committed by Jonathan Druart
parent d60cc56613
commit 8cb6ed24ff
2 changed files with 16 additions and 4 deletions

View file

@ -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;

View file

@ -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 });