From b81937206d03efb49c0c2c5893711dd77e6d2ba8 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 --- 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 211e2e32f3f..154c00e1e8c 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 c70a69184c6..3e4e0354e99 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; @@ -303,16 +304,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" ); - } +}; -- 2.48.1