Bug 40387: Add Test::NoWarnings and replace carp with Koha::Logger

This patch adds Test::NoWarnings to our EDI unit tests. In doing so, it
reminded me that we still had some old carp style error handling in the
process_quote section and that we shoudl replace those with calls to
Koha::Logger instead.

Changes made:
1. Added Test::NoWarnings import to catch any warnings
2. Replace 'carp "Message"' appropriately with
   '$logger->warn("Message")'

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2025-07-18 14:18:08 +01:00 committed by Lucas Gass
parent dda29248ba
commit ac3eced5d3
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 14 additions and 22 deletions

View File

@ -21,7 +21,6 @@ use strict;
use warnings;
use base qw(Exporter);
use utf8;
use Carp qw( carp );
use English qw{ -no_match_vars };
use Business::ISBN;
use DateTime;
@ -69,8 +68,10 @@ sub create_edi_order {
my $ean = $parameters->{ean};
my $branchcode = $parameters->{branchcode};
my $noingest = $parameters->{noingest};
my $logger = Koha::Logger->get( { interface => 'edi' } );
if ( !$basketno || !$ean ) {
carp 'create_edi_order called with no basketno or ean';
$logger->error('create_edi_order called with no basketno or ean');
return;
}
@ -84,7 +85,7 @@ sub create_edi_order {
)->all;
if ( !@orderlines ) {
carp "No orderlines for basket $basketno";
$logger->warn("No orderlines for basket $basketno");
return;
}
@ -111,7 +112,7 @@ sub create_edi_order {
}
unless ($ean_obj) {
carp "No matching EAN found for $ean";
$logger->warn("No matching EAN found for $ean");
return;
}

View File

@ -20,8 +20,8 @@
use Modern::Perl;
use FindBin qw( $Bin );
use Test::More tests => 3;
use Test::Warn;
use Test::NoWarnings;
use Test::More tests => 4;
use Test::MockModule;
use t::lib::Mocks;
@ -817,7 +817,7 @@ subtest 'process_invoice' => sub {
};
subtest 'process_invoice_without_tax_rate' => sub {
plan tests => 4;
plan tests => 3;
$schema->storage->txn_begin;
@ -873,23 +873,14 @@ subtest 'process_invoice_without_tax_rate' => sub {
# Process the invoice - this should not generate warnings about undefined tax rates
my $error;
my $warnings = [];
{
local $SIG{__WARN__} = sub { push @$warnings, $_[0] };
eval {
process_invoice($invoice_message);
1;
} or do {
$error = $@;
};
}
eval {
process_invoice($invoice_message);
1;
} or do {
$error = $@;
};
ok( !$error, 'process_invoice completed without dying when no tax rate present' );
# Check that no warnings about uninitialized values in multiplication were generated
my $tax_warnings = grep { /Use of uninitialized value.*multiplication/ } @$warnings;
is( $tax_warnings, 0, 'No warnings about uninitialized values in multiplication' );
# Verify that orders with tax data exist (means processing completed)
my $orders = $schema->resultset('Aqorder')->search(
{