Bug 23038: Hide expected warnings from tests

When tests are ran, there are 2 warnings that are expected and raised by
DBI.
As they are expected they must be correctly caught and not displayed.

We could have reconnect with PrintError turned off, but then reconnect
with it on.

Test plan:
% prove t/db_dependent/Circulation/MarkIssueReturned.t t/db_dependent/Suggestions.t
Must not display DBI warnings

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2019-06-03 11:40:31 -05:00 committed by Martin Renvoize
parent 40380339f9
commit 04ec6627e2
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
2 changed files with 28 additions and 10 deletions

View file

@ -174,10 +174,18 @@ subtest 'Manually pass a return date' => sub {
$issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
throws_ok
{ $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, 'bad_date', 0 ); }
'Koha::Exceptions::Object::BadValue',
'An exception is thrown on bad date';
{
# Hiding the expected warning displayed by DBI
# DBD::mysql::st execute failed: Incorrect datetime value: 'bad_date' for column 'returndate'
my $stderr;
local *STDERR;
open STDERR, '>', '/dev/null';
throws_ok
{ $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, 'bad_date', 0 ); }
'Koha::Exceptions::Object::BadValue',
'An exception is thrown on bad date';
close STDERR;
}
$schema->storage->txn_rollback;
};

View file

@ -250,12 +250,22 @@ $messages = C4::Letters::GetQueuedMessages({
});
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is email if the borrower has an email');
$mod_suggestion4->{manageddate} = 'invalid date!';
ModSuggestion($mod_suggestion4);
$messages = C4::Letters::GetQueuedMessages({
borrowernumber => $borrowernumber2
});
is (scalar(@$messages), 1, 'No new letter should have been generated if the update raised an error');
{
# Hiding the expected warning displayed by DBI
# DBD::mysql::st execute failed: Incorrect date value: 'invalid date!' for column 'manageddate'
my $stderr;
local *STDERR;
open STDERR, '>', '/dev/null';
$mod_suggestion4->{manageddate} = 'invalid date!';
ModSuggestion($mod_suggestion4);
$messages = C4::Letters::GetQueuedMessages({
borrowernumber => $borrowernumber2
});
close STDERR;
is (scalar(@$messages), 1, 'No new letter should have been generated if the update raised an error');
}
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' );
$suggestion = GetSuggestionInfo($my_suggestionid);