From 8853c3d4a302182eb2c1f013ec6d836d4050e229 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. Sponsored-by: OpenFifth Signed-off-by: Jackie Usher --- .../Koha/Schema/Util/ExceptionTranslator.t | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t b/t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t index 0a978a4124d..56d572cd722 100755 --- a/t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t +++ b/t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t @@ -15,7 +15,7 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with Koha; if not, see . +# along with Koha; if not, see . use Modern::Perl; use Test::NoWarnings; @@ -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.53.0