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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit ac266cad8b)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Martin Renvoize 2025-07-10 16:52:41 +01:00 committed by Paul Derscheid
parent e5eba4f13f
commit 3f5a42a7d0
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
3 changed files with 10 additions and 2 deletions

View File

@ -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} ) {

View File

@ -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 /(?<![?])[+]/, $seg;

View File

@ -3,7 +3,8 @@ use strict;
use warnings;
use FindBin qw( $Bin );
use Test::More tests => 41;
use Test::NoWarnings;
use Test::More tests => 42;
use Koha::EDI;
BEGIN { use_ok('Koha::Edifact') }