Bug 15339: TestBuilder warnings (tests)
authorMartin Persson <xarragon@gmail.com>
Wed, 9 Dec 2015 10:31:12 +0000 (11:31 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 7 Sep 2017 16:35:06 +0000 (13:35 -0300)
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 <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/TestBuilder.t

index 03f58eb..c370b5a 100644 (file)
@@ -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;