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
 <message_broker>
    <hostname>localhost</hostname>
    <port>61613</port>
    <username>guest</username>
    <password>guest</password>
    <vhost></vhost>
 </message_broker>
=> Without this patch the tests fail because the config will overwrite
the env vars.

Signed-off-by: Magnus Enger <magnus@libriotech.no>
Warning goes away and prove works even with the message_broker config.
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 15a272e1e1)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2025-03-10 11:14:42 +01:00 committed by Fridolin Somers
parent 673306f563
commit bb697a165d
No known key found for this signature in database
GPG Key ID: 9A8E73E2A8B96537
2 changed files with 8 additions and 7 deletions

View File

@ -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 = {

View File

@ -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" );
}
};