From 0f5f7043aa6b9eb274c3fb69a2ebee2c6b96f7cf Mon Sep 17 00:00:00 2001 From: Martin Persson Date: Wed, 9 Dec 2015 11:31:12 +0100 Subject: [PATCH] Bug 15339: TestBuilder warnings (tests) Content-Type: text/plain; charset=utf-8 Makes TestBuilder::build() alert the user when unreognized parameters are passed, which happens when the user supplies the column values directly, forgetting the 'value' hash. This patch contains the tests that doubles as a demonstration of the kind of error the patch is intended to prevent. Sponsored-By: Halland County Library Signed-off-by: Jonathan Druart Signed-off-by: Marcel de Rooy --- t/db_dependent/TestBuilder.t | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/TestBuilder.t b/t/db_dependent/TestBuilder.t index 03f58eb..c370b5a 100644 --- a/t/db_dependent/TestBuilder.t +++ b/t/db_dependent/TestBuilder.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 12; +use Test::More tests => 13; use Test::Warn; use File::Basename qw(dirname); @@ -332,7 +332,6 @@ subtest 'Date handling' => sub { my $patron = $builder->build( { source => 'Borrower' } ); is( length( $patron->{updated_on} ), 19, 'A timestamp column value should be YYYY-MM-DD HH:MM:SS' ); is( length( $patron->{dateofbirth} ), 10, 'A date column value should be YYYY-MM-DD' ); - }; subtest 'Default values' => sub { @@ -391,4 +390,25 @@ subtest 'build_object() tests' => sub { }; }; +subtest '->build parameter' => sub { + plan tests => 2; + + # Test to make sure build() warns user of unknown parameters. + warnings_are { + $builder->build({ + source => 'Branch', + values => { + branchcode => 'BRANCH_1' + } + }) + } [], "No warnings on correct use"; + + warnings_like { + $builder->build({ + source => 'Branch', + branchcode => 'BRANCH_2' # This is wrong! + }) + } qr/unknown param/i, "Carp unknown parameters"; +}; + $schema->storage->txn_rollback; -- 2.1.4