From 6ec185abbe2827c0ab050125500853274e607f32 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Sun, 21 Sep 2025 16:10:08 +0100 Subject: [PATCH] Bug 19871: (QA follow-up) Replace symbolic refs with proper mock object class Replace 'no strict refs' usage with a proper TestObject package to avoid Perl::Critic violations while maintaining the same test functionality. The mock object now uses standard OOP patterns instead of symbolic references for method creation. --- .../Koha/Schema/Util/ExceptionTranslator.t | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t b/t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t index 0a978a4124d..3e3626bd7d5 100755 --- a/t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t +++ b/t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t @@ -149,19 +149,28 @@ subtest 'enum_truncation_with_object_value' => sub { $schema->storage->txn_begin; - # Create a mock object with a property accessor - my $mock_object = bless { test_enum => 'invalid_value' }, 'TestObject'; + # Create a mock object class with proper methods + package TestObject { - # Add the can method to simulate a real object - { - no strict 'refs'; - *{"TestObject::can"} = sub { + sub new { + my ( $class, %args ) = @_; + return bless \%args, $class; + } + + sub can { my ( $self, $method ) = @_; - return $method eq 'test_enum' ? sub { return $self->{test_enum} } : undef; - }; - *{"TestObject::test_enum"} = sub { return $_[0]->{test_enum} }; + return $method eq 'test_enum' ? \&test_enum : undef; + } + + sub test_enum { + my ($self) = @_; + return $self->{test_enum}; + } } + # Create a mock object with a property accessor + my $mock_object = TestObject->new( test_enum => 'invalid_value' ); + # Create a mock DBIx::Class::Exception for enum data truncation my $exception = bless { msg => "Data truncated for column 'test_enum'" }, 'DBIx::Class::Exception'; -- 2.51.0