From 0182e7ae84be8b144ca1ff22aa7fe4731c9f8269 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 7 Jul 2025 13:58:37 +0200 Subject: [PATCH] Bug 40317: Remove warnings from Auth_with_shibboleth.t output t/db_dependent/Auth_with_shibboleth.t .. 1/5 GetPreparedLetter called at t/db_dependent/Auth_with_shibboleth.t line 73. EnqueueLetter called at t/db_dependent/Auth_with_shibboleth.t line 80. SendQueuedMessages called with message_id: 42 at t/db_dependent/Auth_with_shibboleth.t line 90. Not sure what exactly is going on here, but warnings_are is not supposed to show the warnings in the output. I think it's because of the logger mock. A workaround is to use a variable we increment then compare to see if we reach the sub. Test plan: % prove t/db_dependent/Auth_with_shibboleth.t should return green without warnings --- t/db_dependent/Auth_with_shibboleth.t | 31 ++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/t/db_dependent/Auth_with_shibboleth.t b/t/db_dependent/Auth_with_shibboleth.t index db6ce0b1cba..b7cfdbbfb2b 100755 --- a/t/db_dependent/Auth_with_shibboleth.t +++ b/t/db_dependent/Auth_with_shibboleth.t @@ -20,9 +20,10 @@ use Modern::Perl; use utf8; -use Test::More tests => 6; +use Test::More tests => 7; use Test::MockModule; use Test::Warn; +use Test::NoWarnings; use CGI qw(-utf8 ); use File::Temp qw(tempdir); @@ -67,17 +68,18 @@ $context->mock( 'interface', sub { return $interface; } ); # Mock Letters: GetPreparedLetter, EnqueueLetter and SendQueuedMessages # We want to test the params my $mocked_letters = Test::MockModule->new('C4::Letters'); +my $sub_called = {}; $mocked_letters->mock( 'GetPreparedLetter', sub { - warn "GetPreparedLetter called"; + $sub_called->{GetPreparedLetter}++; return 1; } ); $mocked_letters->mock( 'EnqueueLetter', sub { - warn "EnqueueLetter called"; + $sub_called->{EnqueueLetter}++; # return a 'message_id' return 42; @@ -87,7 +89,7 @@ $mocked_letters->mock( 'SendQueuedMessages', sub { my $params = shift; - warn "SendQueuedMessages called with message_id: $params->{message_id}"; + $sub_called->{SendQueuedMessages}->{ $params->{message_id} }++; return 1; } ); @@ -172,7 +174,7 @@ subtest "get_login_shib tests" => sub { subtest "checkpw_shib tests" => sub { - plan tests => 54; + plan tests => 56; # Test borrower data my $test_borrowers = [ @@ -251,18 +253,13 @@ subtest "checkpw_shib tests" => sub { $ENV{'emailpro'} = 'me@myemail.com'; $ENV{branchcode} = $library->branchcode; # needed since T::D::C does no longer hides the FK constraint - warnings_are { - ( $retval, $retcard, $retuserid, $retpatron ) = checkpw_shib($shib_login); - } - [ - 'GetPreparedLetter called', - 'EnqueueLetter called', - 'SendQueuedMessages called with message_id: 42' - ], - "WELCOME notice Prepared, Enqueued and Send"; - is( $retval, "1", "user authenticated" ); - is( $retuserid, "test4321", "expected userid returned" ); - is( ref($retpatron), 'Koha::Patron', "expected Koha::Patron object returned" ); + ( $retval, $retcard, $retuserid, $retpatron ) = checkpw_shib($shib_login); + is( $sub_called->{GetPreparedLetter}, 1, 'GetPreparedLetter called' ); + is( $sub_called->{EnqueueLetter}, 1, 'EnqueueLetter called' ); + is( $sub_called->{SendQueuedMessages}->{42}, 1, 'SendQueuedMessages called with message_id: 42' ); + is( $retval, "1", "user authenticated" ); + is( $retuserid, "test4321", "expected userid returned" ); + is( ref($retpatron), 'Koha::Patron', "expected Koha::Patron object returned" ); $logger->debug_is( "koha borrower field to match: userid", "borrower match field debug info" ) ->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )->clear(); -- 2.34.1