.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Test::MockDBI 3pm" .TH Test::MockDBI 3pm "2022-11-27" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Test::MockDBI \- Mocked DBI interface for testing purposes .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Test::MockDBI; \& \& my $mi = Test::MockDBI::get_instance(); \& \& Sets a fake return value for the rows statementhandler \& $mi\->set_retval( method => rows, retval => sub{ return scalar( @somearray ); }); \& \& $mi\->set_retval( method => \*(Aqbind_param\*(Aq, retval => undef); \& Same as: \& $mi\->bad_method(\*(Aqbind_param\*(Aq); \& \& You can also specify return values for specific sqls \& $mi\->set_retval( method => rows, retval => sub{ return scalar( @somearray ); }, sql => \*(Aqselect id from names\*(Aq); \& \& $mi\->set_retval( method => \*(Aqbind_param\*(Aq, retval => undef, sql => \*(Aqselect id from names where id < ?\*(Aq); \& Same as: \& $mi\->bad_method(\*(Aqbind_param\*(Aq, \*(Aqselect id from names where id < ?\*(Aq); .Ve .SH "PUBLIC INTERFACE" .IX Header "PUBLIC INTERFACE" .Vb 1 \& Methods available on the Test::MockDBI instance. .Ve .IP "\fBreset()\fR" 4 .IX Item "reset()" .Vb 1 \& Method for reseting all mock returnvalues \e bad_params etc .Ve .IP "\fBbad_method()\fR" 4 .IX Item "bad_method()" .Vb 1 \& This method is basically a alias for calling set_retval with the return value undef. \& \& Args: \& $method_name \- The name of the method which should return undef \& $matching_sql (Optional) \- The sql matching condition \& \& Returns: \& On success: 1 \& On failure: undef \& \& The method also supports calling the method with the following arguments: \& $method_name, $dbi_testing_type, $matching_sql \& This will issue a warning as it is deprecated. .Ve .IP "\fBbad_param()\fR" 4 .IX Item "bad_param()" .Vb 3 \& Args: \& $p_value \- The value that will cause bind_param to return undef \& $sql (Optional) \- The sql matching condition \& \& Returns: \& On success: 1 \& On failure: undef \& \& The method also supports calling the method with the following arguments: \& $dbi_testing_type, $p_num, $p_value \& This will issue a warning as it is deprecated. .Ve .IP "\fBset_retval()\fR" 4 .IX Item "set_retval()" .Vb 1 \& Method for setting a return value for the specific method. \& \& Args:(Keys in a hash) \& method \- The method that should return the provided value \& retval \- The data which should be returned \& sql (Optional) \- Matching sql. The return value will only be \& returned for the provided method if the sql matches \& a regex compiled by using this string \& \& Returnvalues: \& On success: 1 \& On failure: undef \& \& Example usage: \& \& #fetchrow_hashref will shift one hashref from the list each time its called if the sql matches the sql provided, this will happend \& #until the return list is empty. \& $inst\->set_retval( method => \*(Aqfetchrow_hashref\*(Aq, \& retval => [ { letter => \*(Aqa\*(Aq }, { letter => \*(Aqb\*(Aq }, { letter => \*(Aqc\*(Aq } ], \& sql => \*(Aqselect * from letters\*(Aq ) \& \& #execute will default return undef \& $inst\->set_retval( method => \*(Aqexecute\*(Aq, retval => undef) \& \& #Execute will return 10 for sql \*(Aqselect * from cars\*(Aq \& $inst\->set_retval( method => \*(Aqexecute\*(Aq, retval => undef); \& $inst\->set_retval( method => \*(Aqexecute\*(Aq, retval => 10, sql => \*(Aqselect * from cars\*(Aq); .Ve .IP "\fBset_inout_value()\fR" 4 .IX Item "set_inout_value()" .Vb 3 \& Special method for handling inout params. \& In this method you can provided the value that the inout param should have \& after execute is called. \& \& Args: \& $sql \- The sql that this rule should apply for \& $p_num \- The parameter number of the inout parameter \& $value \- The value that the inout parameter should have after execute \& \& Returns: \& On success: 1 \& On failure: undef \& \& Example: .Ve .SH "PRIVATE INTERFACE" .IX Header "PRIVATE INTERFACE" .Vb 1 \& Methods used by the package internally. Should not be called from an external package. .Ve .IP "\fB_clear_dbi_err_errstr()\fR" 4 .IX Item "_clear_dbi_err_errstr()" .Vb 2 \& Helper method used by the fake DBI::st and DBI::db to clear out \& the $obj\->{err} and $obj\->{errstr} on each method call. \& \& Should not be called from an external script\epackage. .Ve .IP "\fB_set_dbi_err_errstr()\fR" 4 .IX Item "_set_dbi_err_errstr()" .Vb 3 \& Helper method used by the fake DBI::st and DBI::db to set the \& $obj\->{err}, $obj\->{errstr}, $DBI::err and $DBI::errstr. \& This method also handles RaiseError and PrintError attributes. \& \& Args: \& $obj \- Instance of DBI::st or DBI::db \& %args \- A hash with the following keys: \& err \- The numeric error code to be set \& errstr \- The user friendly DBI error message. \& \& Returns: \& On success : 1 \& On failure : undef .Ve .IP "_set_fake_dbi_err_errstr" 4 .IX Item "_set_fake_dbi_err_errstr" .PD 0 .IP "\fB_has_inout_value()\fR" 4 .IX Item "_has_inout_value()" .PD .Vb 3 \& Helper method used by the DBI::db and DBI::st packages. \& The method searches to see if there is specified a value for a \& inout variable. \& \& If called in SCALAR context it return 1/undef based on if the \& parameter bound as $p_num has a predefined return value set. \& \& If called in LIST context the method returns and array with \& 1/undef in position 0 which indicates the same as when the method \& is called in SCALAR context. The second element of the list is the \& value that should be applied to the inout parameter. .Ve .IP "\fB_has_fake_retval()\fR" 4 .IX Item "_has_fake_retval()" .Vb 3 \& Method for identifing if a method has a predefined return value set. \& If the SQL parameter is provided \& this will have precedence over the default value. \& \& If the method is called in SCALAR context it will return 1\eundef based on \& if the method has a predefined return value set. \& \& If the method is called in LIST context it will return a list with 1/undef at \& index 0 which indicates the same as when called in SCALAR context. index 1 will \& contain a reference to the actual return value that should be returned by the method. \& This value may be undef. .Ve .IP "\fB_is_bad_bind_param()\fR" 4 .IX Item "_is_bad_bind_param()" .Vb 2 \& Method for identifing if a bind parameters value is predefined as unwanted. \& The configuration for the provided SQL will have precedence over the default configured behaviour. \& \& When called it will return 1\eundef based on \& if the provided value should make the bind_param method fail. .Ve .SH "CLASS INTERFACE" .IX Header "CLASS INTERFACE" .IP "\fBget_instance()\fR" 4 .IX Item "get_instance()" .Vb 1 \& Method for retrieving the current Test::MockDBI instance .Ve .PP .Vb 2 \& This is basically a copy\epaste from the DBI package itself. \& The method is used inside the prepare_cached method .Ve .PP .Vb 2 \& This is basically a copy\epaste from the DBI package itself. \& The method is used inside the prepare_cached method .Ve .PP .Vb 2 \& This is basically a copy\epaste from the DBI package itself. \& The method is used inside the prepare_cached method .Ve .PP .Vb 1 \& Mocked DBI\->connect method. \& \& The method takes the same arguments as the usual DBI\->connect method. \& It returns a $dbh which has ref DBI::db .Ve .SH "AUTHOR" .IX Header "AUTHOR" Mark Leighton Fisher, .PP Minor modifications (version 0.62 onwards) by Andreas Faafeng .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2004, Fisher's Creek Consulting, \s-1LLC.\s0 Copyright 2004, DeepData, Inc. .SH "LICENSE" .IX Header "LICENSE" This code is released under the same licenses as Perl itself.