From dd625a30df8f03e5c95cd0ec39231c2a8e0c6d1c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 10 Jul 2025 16:52:41 +0100 Subject: [PATCH] Bug 40386: Remove warnings from EDI when running tests This patch fixes several warnings that occur when running Edifact tests: 1. Changed `my $self = ()` to `my $self = {}` in Koha::Edifact constructor to properly initialize as hashref instead of empty list 2. Added null/empty checks in Koha::Edifact::Segment::_parse_seg() to prevent warnings when processing undefined or empty segments 3. Added null/empty checks in Koha::Edifact::Segment::_get_elements() to handle undefined segments gracefully 4. Added Test::NoWarnings to t/Edifact.t to catch any remaining warnings These changes eliminate "Use of uninitialized value" warnings and ensure clean test runs without affecting EDI functionality. Test plan: 1. Run prove t/Edifact.t and verify no warnings are displayed 2. Test EDI message processing to ensure no regression --- Koha/Edifact.pm | 2 +- Koha/Edifact/Segment.pm | 7 +++++++ t/Edifact.t | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Koha/Edifact.pm b/Koha/Edifact.pm index 7479a9b42b5..ada773b9ca4 100644 --- a/Koha/Edifact.pm +++ b/Koha/Edifact.pm @@ -36,7 +36,7 @@ my $separator = { sub new { my ( $class, $param_hashref ) = @_; my $transmission; - my $self = (); + my $self = {}; if ( $param_hashref->{filename} ) { if ( $param_hashref->{transmission} ) { diff --git a/Koha/Edifact/Segment.pm b/Koha/Edifact/Segment.pm index 563b3e72224..a9600168e0a 100644 --- a/Koha/Edifact/Segment.pm +++ b/Koha/Edifact/Segment.pm @@ -86,6 +86,10 @@ sub as_string { # parse a string into fields sub _parse_seg { my $s = shift; + + # Handle undefined or empty segments + return { tag => '', elem_arr => [] } unless defined $s && length $s >= 3; + my $e = { tag => substr( $s, 0, 3 ), elem_arr => _get_elements( substr( $s, 3 ) ), @@ -100,6 +104,9 @@ sub _parse_seg { sub _get_elements { my $seg = shift; + # Handle undefined or empty segments + return [] unless defined $seg; + $seg =~ s/^[+]//; # dont start with a dummy element` my @elem_array = map { _components($_) } split /(? 41; +use Test::NoWarnings; +use Test::More tests => 42; use Koha::EDI; BEGIN { use_ok('Koha::Edifact') } -- 2.50.1