use
lib
"$RealBin/../lib"
;
my
(
$host
,
$port
);
my
$mockEmailTransport
= Test::MockModule->new(
'Email::Sender::Transport::SMTP'
);
$mockEmailTransport
->mock(
'new'
,
sub
{
my
$hr_params
=
$_
[1];
$host
=
$$hr_params
{host};
$port
=
$$hr_params
{port};
});
$mockEmailTransport
->mock(
'host'
,
sub
{
shift
;
$host
=
shift
;});
$mockEmailTransport
->mock(
'port'
,
sub
{
shift
;
$port
=
shift
;});
$ipchgmon::opt_mailserver
=
'Outbound mail'
;
$ipchgmon::opt_mailport
= 25;
ipchgmon::build_transport;
is
$host
,
'Outbound mail'
,
'Host populated correctly'
;
is
$port
, 25,
'Port populated correctly'
;
undef
$host
;
undef
$port
;
undef
$ipchgmon::opt_mailport
;
$ipchgmon::opt_mailserver
=
'Outbound mail 2'
;
ipchgmon::build_transport;
is
$host
,
'Outbound mail 2'
,
'Host populated correctly when port omitted'
;
is
$port
, 25,
'Port populated correctly when omitted'
;
done_testing();