1Plack::Test::Agent(3) User Contributed Perl DocumentationPlack::Test::Agent(3)
2
3
4

NAME

6       Plack::Test::Agent - OO interface for testing low-level Plack/PSGI apps
7

VERSION

9       version 1.5
10
11   SYNOPSIS
12           use Test::More;
13           use Plack::Test::Agent;
14
15           my $app          = sub { ... };
16           my $local_agent  = Plack::Test::Agent->new( app => $app );
17           my $server_agent = Plack::Test::Agent->new(
18                               app    => $app,
19                               server => 'HTTP::Server::Simple' );
20
21           my $local_res    = $local_agent->get( '/' );
22           my $server_res   = $server_agent->get( '/' );
23
24           ok $local_res->is_success,  'local GET / should succeed';
25           ok $server_res->is_success, 'server GET / should succeed';
26
27   DESCRIPTION
28       "Plack::Test::Agent" is an OO interface to test PSGI applications. It
29       can perform GET and POST requests against PSGI applications either in
30       process or over HTTP through a Plack::Handler compatible backend.
31
32       NOTE: This is an experimental module and its interface may change.
33
34   CONSTRUCTION
35       "new"
36
37       The "new" constructor creates an instance of "Plack::Test::Agent". This
38       constructor takes one mandatory named argument and several optional
39       arguments.
40
41       ·   "app" is the mandatory argument. You must provide a PSGI
42           application to test.
43
44       ·   "server" is an optional argument. When provided,
45           "Plack::Test::Agent" will attempt to start a PSGI handler and will
46           communicate via HTTP to the application running through the
47           handler. See Plack::Loader for details on selecting the appropriate
48           server.
49
50       ·   "host" is an optional argument representing the name or IP address
51           for the server to use. The default is "localhost".
52
53       ·   "port" is an optional argument representing the TCP port to for the
54           server to use. If not provided, the service will run on a randomly
55           selected available port outside of the IANA reserved range. (See
56           Test::TCP for details on the selection of the port number.)
57
58       ·   "ua" is an optional argument of something which conforms to the
59           LWP::UserAgent interface such that it provides a "request" method
60           which takes an HTTP::Request object and returns an HTTP::Response
61           object. The default is an instance of "LWP::UserAgent".
62
63       ·   "jar" is an optional argument for a HTTP::Cookies instance that
64           will be used as cookie jar for the requests, by default plain one
65           is created.
66
67   METHODS
68       This class provides several useful methods:
69
70       "get"
71
72       This method takes a URI and makes a "GET" request against the PSGI
73       application with that URI. It returns an HTTP::Response object
74       representing the results of that request.
75
76       "post"
77
78       This method takes a URI and makes a "POST" request against the PSGI
79       application with that URI. It returns an HTTP::Response object
80       representing the results of that request. As an optional second
81       parameter, pass an array reference of key/value pairs for the form
82       content:
83
84           $agent->post( '/edit_user',
85               [
86                   shoe_size => '10.5',
87                   eye_color => 'blue green',
88                   status    => 'twin',
89               ]);
90
91       "execute_request"
92
93       This method takes an HTTP::Request, performs it against the bound app,
94       and returns an HTTP::Response. This allows you to craft your own
95       requests directly.
96
97       "get_mech"
98
99       Used internally to create a default UserAgent, if none is provided to
100       the constructor.  Returns a Test::WWW::Mechanize::Bound object.
101
102       "normalize_uri"
103
104       Used internally to ensure that all requests use the correct scheme,
105       host and port.  The scheme and host default to "http" and "localhost"
106       respectively, while the port is determined by Test::TCP.
107
108       "start_server"
109
110       Starts a test server via Test::TCP.  If a "server" arg has been
111       provided to the constructor, it will use this class to load a server.
112       Defaults to letting Plack::Loader decide which server class to use.
113
114   CREDITS
115       Thanks to Zbigniew Łukasiak and Tatsuhiko Miyagawa for suggestions.
116

AUTHORS

118       ·   chromatic <chromatic@wgz.org>
119
120       ·   Dave Rolsky <autarch@urth.org>
121
122       ·   Ran Eilam <ran.eilam@gmail.com>
123
124       ·   Olaf Alders <olaf@wundercounter.com>
125

CONTRIBUTORS

127       ·   Dave Rolsky <drolsky@maxmind.com>
128
129       ·   Olaf Alders <oalders@maxmind.com>
130
131       ·   Ran Eilam <reilam@maxmind.com>
132
133       ·   Syohei YOSHIDA <syohex@gmail.com>
134
135       ·   Torsten Raudssus <torsten@raudss.us>
136
138       This software is copyright (c) 2011 by chromatic.
139
140       This is free software; you can redistribute it and/or modify it under
141       the same terms as the Perl 5 programming language system itself.
142
143
144
145perl v5.32.0                      2020-10-06             Plack::Test::Agent(3)
Impressum