]> Dogcows Code - chaz/graphql-client/blob - t/lib/MockUA.pm
add tests and many fixes
[chaz/graphql-client] / t / lib / MockUA.pm
1 package MockUA;
2 # ABSTRACT: HTTP::AnyUA backend for testing GraphQL::Client::http
3
4 use warnings;
5 use strict;
6
7 use Scalar::Util qw(blessed);
8 use namespace::clean;
9
10 use parent 'HTTP::AnyUA::Backend';
11
12 =method response
13
14 $response = $backend->response;
15 $response = $backend->response($response);
16
17 Get and set the response hashref or L<Future> that this backend will always respond with.
18
19 =cut
20
21 sub response { @_ == 2 ? $_[0]->{response} = pop : $_[0]->{response} }
22
23 =method requests
24
25 @requests = $backend->requests;
26
27 Get the requests the backend has handled so far.
28
29 =cut
30
31 sub requests { @{$_[0]->{requests} || []} }
32
33 sub response_is_future { blessed($_[0]->{response}) && $_[0]->{response}->isa('Future') }
34
35 sub request {
36 my $self = shift;
37
38 push @{$self->{requests} ||= []}, [@_];
39
40 return $self->response || {
41 success => '',
42 status => 599,
43 reason => 'Internal Exception',
44 content => "No response mocked.\n",
45 };
46 }
47
48 1;
This page took 0.034524 seconds and 4 git commands to generate.