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.4
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   METHODS
64       This class provides several useful methods:
65
66       "get"
67
68       This method takes a URI and makes a "GET" request against the PSGI
69       application with that URI. It returns an HTTP::Response object
70       representing the results of that request.
71
72       "post"
73
74       This method takes a URI and makes a "POST" request against the PSGI
75       application with that URI. It returns an HTTP::Response object
76       representing the results of that request. As an optional second
77       parameter, pass an array reference of key/value pairs for the form
78       content:
79
80           $agent->post( '/edit_user',
81               [
82                   shoe_size => '10.5',
83                   eye_color => 'blue green',
84                   status    => 'twin',
85               ]);
86
87       "execute_request"
88
89       This method takes an HTTP::Request, performs it against the bound app,
90       and returns an HTTP::Response. This allows you to craft your own
91       requests directly.
92
93       "get_mech"
94
95       Used internally to create a default UserAgent, if none is provided to
96       the constructor.  Returns a Test::WWW::Mechanize::Bound object.
97
98       "normalize_uri"
99
100       Used internally to ensure that all requests use the correct scheme,
101       host and port.  The scheme and host default to "http" and "localhost"
102       respectively, while the port is determined by Test::TCP.
103
104       "start_server"
105
106       Starts a test server via Test::TCP.  If a "server" arg has been
107       provided to the constructor, it will use this class to load a server.
108       Defaults to letting Plack::Loader decide which server class to use.
109
110   CREDITS
111       Thanks to Zbigniew Łukasiak and Tatsuhiko Miyagawa for suggestions.
112

AUTHORS

114       ·   chromatic <chromatic@wgz.org>
115
116       ·   Dave Rolsky <autarch@urth.org>
117
118       ·   Ran Eilam <ran.eilam@gmail.com>
119
120       ·   Olaf Alders <olaf@wundercounter.com>
121

CONTRIBUTORS

123       ·   Dave Rolsky <drolsky@maxmind.com>
124
125       ·   Olaf Alders <oalders@maxmind.com>
126
127       ·   Ran Eilam <reilam@maxmind.com>
128
130       This software is copyright (c) 2011 - 2015 by chromatic.
131
132       This is free software; you can redistribute it and/or modify it under
133       the same terms as the Perl 5 programming language system itself.
134
135
136
137perl v5.28.1                      2015-01-06             Plack::Test::Agent(3)
Impressum