X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fgraphql-client;a=blobdiff_plain;f=t%2Flib%2FMockTransport.pm;fp=t%2Flib%2FMockTransport.pm;h=7e4159fc387aee8388ee0f12dfdcf01a33b61ed6;hp=0000000000000000000000000000000000000000;hb=6ceb671d38a8564d8bbe6e52a33e54ebdc4ca282;hpb=dfa1c3680f0f1e5ccc6d85b4fa5a4916bf31b23d;ds=sidebyside diff --git a/t/lib/MockTransport.pm b/t/lib/MockTransport.pm new file mode 100644 index 0000000..7e4159f --- /dev/null +++ b/t/lib/MockTransport.pm @@ -0,0 +1,38 @@ +package MockTransport; +# ABSTRACT: A backend for testing HTTP::AnyUA + +use warnings; +use strict; + +sub new { bless {}, shift } + +=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 execute { + my $self = shift; + + push @{$self->{requests} ||= []}, [@_]; + + return $self->response; +} + +1;