From bb697a165d875a118f2e4306c6ae45fba96dd349 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 10 Mar 2025 11:14:42 +0100 Subject: [PATCH] Bug 39286: Use mock_config instead of env vars Bug 35655 needed to mock the config, but instead introduced new env variables. Test plan: prove t/db_dependent/Koha/BackgroundJob.t should still return green Bonus 1: no more warning t/db_dependent/Koha/BackgroundJob.t .. 1/6 Cannot connect to broker Failed to connect: Error connecting to not_localhost:99999: Invalid argument at /usr/share/perl5/Net/Stomp.pm line 27.; giving up at /usr/share/perl5/Net/Stomp.pm line 27. Bonus 2: tests are passing even if you have 'message_broker' in the config To test this, add the following entry to $KOHA_CONf then prove again localhost 61613 guest guest => Without this patch the tests fail because the config will overwrite the env vars. Signed-off-by: Magnus Enger Warning goes away and prove works even with the message_broker config. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Katrin Fischer (cherry picked from commit 15a272e1e18229c820320fe4f973aff30bc88154) Signed-off-by: Fridolin Somers --- Koha/BackgroundJob.pm | 4 ++-- t/db_dependent/Koha/BackgroundJob.t | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 70e8339687..56b13fd8e4 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -69,8 +69,8 @@ sub connect { return unless $notification_method eq 'STOMP'; - my $hostname = $ENV{KOHA_STOMP_HOSTNAME} // 'localhost'; - my $port = $ENV{KOHA_STOMP_PORT} // '61613'; + my $hostname = 'localhost'; + my $port = '61613'; my $config = C4::Context->config('message_broker'); my $credentials = { diff --git a/t/db_dependent/Koha/BackgroundJob.t b/t/db_dependent/Koha/BackgroundJob.t index 35f8fb4e7d..fbbeb7e106 100755 --- a/t/db_dependent/Koha/BackgroundJob.t +++ b/t/db_dependent/Koha/BackgroundJob.t @@ -22,6 +22,7 @@ use Encode; use Test::More tests => 6; use Test::MockModule; use Test::Exception; +use Test::Warn; use Koha::Database; use Koha::BackgroundJobs; @@ -299,16 +300,16 @@ subtest 'decoded_data() and set_encoded_data() tests' => sub { }; subtest 'decoded_data() and set_encoded_data() tests' => sub { - plan tests => 2; + plan tests => 3; - $ENV{KOHA_STOMP_HOSTNAME} = "not_localhost"; - $ENV{KOHA_STOMP_PORT} = "99999"; + t::lib::Mocks::mock_config( 'message_broker', { hostname => 'not_localhost', port => '99999' } ); t::lib::Mocks::mock_preference('JobsNotificationMethod', 'STOMP'); - my $job = Koha::BackgroundJob->connect(); + my $job; + warning_like { $job = Koha::BackgroundJob->connect() } qr{Cannot connect to broker}; is( $job, undef, "Return undef if unable to connect when using stomp" ); t::lib::Mocks::mock_preference('JobsNotificationMethod', 'polling'); $job = Koha::BackgroundJob->connect(); is( $job, undef, "Return undef if using polling" ); -} +};