From 9ebf9e407d4e4427f1241017d63b97e6688a209c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 18 Jul 2025 14:18:08 +0100 Subject: [PATCH] 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 --- Koha/EDI.pm | 9 +++++---- t/db_dependent/Koha/EDI.t | 27 +++++++++------------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 4a36f15b384..58b3209fd14 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -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; } diff --git a/t/db_dependent/Koha/EDI.t b/t/db_dependent/Koha/EDI.t index 9f037bd0eb4..810c60bc062 100755 --- a/t/db_dependent/Koha/EDI.t +++ b/t/db_dependent/Koha/EDI.t @@ -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( { -- 2.39.5