summaryrefslogtreecommitdiffstats
path: root/extensions/PhabBugz/t
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/PhabBugz/t')
-rw-r--r--extensions/PhabBugz/t/basic.t27
-rw-r--r--extensions/PhabBugz/t/feed-daemon-guts.t12
2 files changed, 20 insertions, 19 deletions
diff --git a/extensions/PhabBugz/t/basic.t b/extensions/PhabBugz/t/basic.t
index 9a6723ccb..af92dc64f 100644
--- a/extensions/PhabBugz/t/basic.t
+++ b/extensions/PhabBugz/t/basic.t
@@ -17,6 +17,7 @@ use Test::More;
use Test2::Tools::Mock;
use Data::Dumper;
use JSON::MaybeXS;
+use Bugzilla::Test::Util qw(mock_useragent_tx);
use Carp;
use Try::Tiny;
@@ -98,13 +99,13 @@ my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
# Same members in both
do {
- my $UserAgent = mock 'LWP::UserAgent' => (
+ my $UserAgent = mock 'Mojo::UserAgent' => (
override => [
'post' => sub {
- my ($self, $url, $params) = @_;
+ my ($self, $url, undef, $params) = @_;
my $data = decode_json($params->{params});
is_deeply($data->{transactions}, [], 'no-op');
- return mock({is_error => 0, content => '{}'});
+ return mock_useragent_tx('{}');
},
],
);
@@ -119,14 +120,14 @@ do {
# Project has members not in group
do {
- my $UserAgent = mock 'LWP::UserAgent' => (
+ my $UserAgent = mock 'Mojo::UserAgent' => (
override => [
'post' => sub {
- my ($self, $url, $params) = @_;
+ my ($self, $url, undef, $params) = @_;
my $data = decode_json($params->{params});
my $expected = [ { type => 'members.remove', value => ['foo'] } ];
is_deeply($data->{transactions}, $expected, 'remove foo');
- return mock({is_error => 0, content => '{}'});
+ return mock_useragent_tx('{}');
},
]
);
@@ -139,14 +140,14 @@ do {
# Group has members not in project
do {
- my $UserAgent = mock 'LWP::UserAgent' => (
+ my $UserAgent = mock 'Mojo::UserAgent' => (
override => [
'post' => sub {
- my ($self, $url, $params) = @_;
+ my ($self, $url, undef, $params) = @_;
my $data = decode_json($params->{params});
my $expected = [ { type => 'members.add', value => ['foo'] } ];
is_deeply($data->{transactions}, $expected, 'add foo');
- return mock({is_error => 0, content => '{}'});
+ return mock_useragent_tx('{}');
},
]
);
@@ -164,10 +165,10 @@ do {
'update' => sub { 1 },
],
);
- my $UserAgent = mock 'LWP::UserAgent' => (
+ my $UserAgent = mock 'Mojo::UserAgent' => (
override => [
'post' => sub {
- my ($self, $url, $params) = @_;
+ my ($self, $url, undef, $params) = @_;
if ($url =~ /differential\.revision\.search/) {
my $content = <<JSON;
{
@@ -215,10 +216,10 @@ do {
}
}
JSON
- return mock { is_error => 0, content => $content };
+ return mock_useragent_tx($content);
}
else {
- return mock { is_error => 1, message => "bad request" };
+ return mock_useragent_tx("bad request");
}
},
],
diff --git a/extensions/PhabBugz/t/feed-daemon-guts.t b/extensions/PhabBugz/t/feed-daemon-guts.t
index 376af18e4..0c508be98 100644
--- a/extensions/PhabBugz/t/feed-daemon-guts.t
+++ b/extensions/PhabBugz/t/feed-daemon-guts.t
@@ -12,7 +12,7 @@ use lib qw( . lib local/lib/perl5 );
BEGIN { $ENV{LOG4PERL_CONFIG_FILE} = 'log4perl-t.conf' }
use Bugzilla::Test::MockDB;
use Bugzilla::Test::MockParams;
-use Bugzilla::Test::Util qw(create_user);
+use Bugzilla::Test::Util qw(create_user mock_useragent_tx);
use Test::More;
use Test2::Tools::Mock;
use Try::Tiny;
@@ -31,7 +31,7 @@ Bugzilla->error_mode(ERROR_MODE_TEST);
my $phab_bot = create_user(PHAB_AUTOMATION_USER, '*');
-my $UserAgent = mock 'LWP::UserAgent' => ();
+my $UserAgent = mock 'Mojo::UserAgent' => ();
{
SetParam('phabricator_enabled', 0);
@@ -54,9 +54,9 @@ my $UserAgent = mock 'LWP::UserAgent' => ();
}
my @bad_response = (
- ['http error', mock({ is_error => 1, message => 'some http error' }) ],
- ['invalid json', mock({ is_error => 0, content => '<xml>foo</xml>' })],
- ['json containing error code', mock({ is_error => 0, content => encode_json({error_code => 1234 }) })],
+ ['http error', mock_useragent_tx("doesn't matter", sub { $_->code(500) }) ],
+ ['invalid json', mock_useragent_tx('<xml>foo</xml>') ],
+ ['json containing error code', mock_useragent_tx(encode_json({error_code => 1234 }))],
);
SetParam(phabricator_enabled => 1);
@@ -67,7 +67,7 @@ foreach my $bad_response (@bad_response) {
my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
$UserAgent->override(
post => sub {
- my ( $self, $url, $params ) = @_;
+ my ( $self, $url, undef, $params ) = @_;
return $bad_response->[1];
}
);