X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fgraphql-client;a=blobdiff_plain;f=t%2Flib%2FMockUA.pm;fp=t%2Flib%2FMockUA.pm;h=3ee2d703d35afcb21be0d095bdf4d4eafecb0f20;hp=0000000000000000000000000000000000000000;hb=6ceb671d38a8564d8bbe6e52a33e54ebdc4ca282;hpb=dfa1c3680f0f1e5ccc6d85b4fa5a4916bf31b23d diff --git a/t/lib/MockUA.pm b/t/lib/MockUA.pm new file mode 100644 index 0000000..3ee2d70 --- /dev/null +++ b/t/lib/MockUA.pm @@ -0,0 +1,48 @@ +package MockUA; +# ABSTRACT: HTTP::AnyUA backend for testing GraphQL::Client::http + +use warnings; +use strict; + +use Scalar::Util qw(blessed); +use namespace::clean; + +use parent 'HTTP::AnyUA::Backend'; + +=method response + + $response = $backend->response; + $response = $backend->response($response); + +Get and set the response hashref or L that this backend will always respond with. + +=cut + +sub response { @_ == 2 ? $_[0]->{response} = pop : $_[0]->{response} } + +=method requests + + @requests = $backend->requests; + +Get the requests the backend has handled so far. + +=cut + +sub requests { @{$_[0]->{requests} || []} } + +sub response_is_future { blessed($_[0]->{response}) && $_[0]->{response}->isa('Future') } + +sub request { + my $self = shift; + + push @{$self->{requests} ||= []}, [@_]; + + return $self->response || { + success => '', + status => 599, + reason => 'Internal Exception', + content => "No response mocked.\n", + }; +} + +1;