1Test::Mock::LWP(3) User Contributed Perl Documentation Test::Mock::LWP(3)
2
3
4
6 Test::Mock::LWP - Easy mocking of LWP packages
7
9 Make LWP packages to make testing easier.
10
11 use Test::Mock::LWP;
12
13 # Setup fake response content and code
14 $Mock_response->mock( content => sub { 'foo' } );
15 $Mock_resp->mock( code => sub { 201 } );
16
17 # Validate args passed to request constructor
18 is_deeply $Mock_request->new_args, \@expected_args;
19
20 # Validate request headers
21 is_deeply [ $Mock_req->next_call ],
22 [ 'header', [ 'Accept', 'text/plain' ] ];
23
24 # Special User Agent Behaviour
25 $Mock_ua->mock( request => sub { die 'foo' } );
26
28 This package arises from duplicating the same code to mock LWP et al in
29 several different modules I've written. This version is very
30 minimalist, but works for my needs so far. I'm very open to new
31 suggestions and improvements.
32
34 The following variables are exported by default:
35
36 $Mock_ua
37 The mock LWP::UserAgent object - a Test::MockObject object
38
39 $Mock_req, $Mock_request
40 The mock HTTP::Request object - a Test::MockObject object
41
42 $Mock_resp, $Mock_response
43 The mock HTTP::Response object - a Test::MockObject object
44
46 Luke Closs, "<test-mock-lwp at 5thplane.com>"
47
49 Please report any bugs or feature requests through the web interface at
50 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Mock-LWP>. I will
51 be notified, and then you'll automatically be notified of progress on
52 your bug as I make changes.
53
55 You can find documentation for this module with the perldoc command.
56
57 perldoc Test::Mock::LWP
58
59 You can also look for information at:
60
61 • AnnoCPAN: Annotated CPAN documentation
62
63 <http://annocpan.org/dist/Test-Mock-LWP>
64
65 • CPAN Ratings
66
67 <http://cpanratings.perl.org/d/Test-Mock-LWP>
68
69 • RT: CPAN's request tracker
70
71 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Mock-LWP>
72
73 • Search CPAN
74
75 <http://search.cpan.org/dist/Test-Mock-LWP>
76
79 Copyright 2006 Luke Closs, all rights reserved.
80
81 This program is free software; you can redistribute it and/or modify it
82 under the same terms as Perl itself.
83
84
85
86perl v5.36.0 2022-07-22 Test::Mock::LWP(3)