our
@EXPORT
=
qw(get_mock_client_no_auth get_mock_client_with_auth read_file_content)
;
sub
get_mock_client_no_auth {
my
$properties_file
=
File::Spec->catdir(dirname($0),
qw(testdata googleads_mock.properties)
);
my
$api_client
=
Google::Ads::GoogleAds::Client->new({
properties_file
=>
$properties_file
});
$api_client
= Test::MockObject::Extends->new(
$api_client
);
$api_client
->mock(
"_get_auth_handler"
,
sub
{
return
undef
; });
return
$api_client
;
}
sub
get_mock_client_with_auth {
my
$properties_file
=
File::Spec->catdir(dirname($0),
qw(testdata googleads_mock.properties)
);
my
$api_client
=
Google::Ads::GoogleAds::Client->new({
properties_file
=>
$properties_file
});
my
$auth_handler
= Test::MockObject->new();
$auth_handler
->mock(
"prepare_request"
,
sub
{
return
HTTP::Request->new(); });
$api_client
= Test::MockObject::Extends->new(
$api_client
);
$api_client
->mock(
"_get_auth_handler"
,
sub
{
return
$auth_handler
; });
return
$api_client
;
}
sub
read_file_content {
my
$file
= File::Spec->catdir(dirname($0),
@_
);
return
do
{
open
(DATA,
"<:encoding(UTF-8)"
,
$file
)
or
die
(
"Can't open \$file\": $!\n"
);
local
$/;
<DATA>;
};
}
sub
__read_properties {
my
$properties_file
=
shift
;
open
(PROPS,
"< $properties_file"
) or
die
"Unable to read properties file."
;
my
$properties
= Config::Properties->new();
$properties
->load(
*PROPS
);
return
$properties
;
}
return
1;