From 01d9ba50404630b09912fcbd32f5c89e019da9c9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 15 Jul 2025 11:43:33 +0200 Subject: [PATCH] Bug 40374: Remove warnings from Koha/Booking.t t/db_dependent/Koha/Booking.t .. 1/2 DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Duplicate entry '7' for key 'PRIMARY' at /kohadevbox/koha/Koha/Object.pm line 174 DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Data truncated for column 'status' at row 1 at /kohadevbox/koha/Koha/Object.pm line 174 --- t/db_dependent/Koha/Booking.t | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/t/db_dependent/Koha/Booking.t b/t/db_dependent/Koha/Booking.t index f1fba22d660..a63d37b120f 100755 --- a/t/db_dependent/Koha/Booking.t +++ b/t/db_dependent/Koha/Booking.t @@ -20,7 +20,10 @@ use Modern::Perl; use utf8; -use Test::More tests => 2; +use Test::More tests => 3; +use Test::NoWarnings; + +use Test::Warn; use Test::Exception; @@ -369,7 +372,7 @@ subtest 'store() tests' => sub { }; subtest 'confirmation notice trigger' => sub { - plan tests => 2; + plan tests => 4; # FIXME: This is a bandaid solution to prevent test failures when running # the Koha_Main_My8 job because notices are not added at upgrade time. @@ -412,7 +415,16 @@ subtest 'store() tests' => sub { )->count; # Reuse previous booking to produce a clash - eval { $booking = Koha::Booking->new( $booking->unblessed )->store }; + warning_like( + sub { + throws_ok { + Koha::Booking->new( $booking->unblessed )->store + } + 'Koha::Exceptions::Object::DuplicateID', + 'Exception is thrown correctly'; + }, + qr{Duplicate entry '(.*?)' for key '(.*\.?)PRIMARY'} + ); my $post_notices_count = Koha::Notice::Messages->search( { @@ -612,12 +624,17 @@ subtest 'store() tests' => sub { }; subtest 'status change exception' => sub { - plan tests => 2; + plan tests => 3; $booking->discard_changes; my $status = $booking->status; - throws_ok { $booking->update( { status => 'blah' } ) } 'Koha::Exceptions::Object::BadValue', - 'Throws exception when passed booking status would fail enum constraint'; + warning_like( + sub { + throws_ok { $booking->update( { status => 'blah' } ) } 'Koha::Exceptions::Object::BadValue', + 'Throws exception when passed booking status would fail enum constraint'; + }, + qr{Data truncated for column 'status'} + ); # Status unchanged $booking->discard_changes; -- 2.34.1