Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

test::mock::lwp(3pm) [debian man page]

Test::Mock::LWP(3pm)					User Contributed Perl Documentation				      Test::Mock::LWP(3pm)

NAME
Test::Mock::LWP - Easy mocking of LWP packages SYNOPSIS
Make LWP packages to make testing easier. use Test::Mock::LWP; # Setup fake response content and code $Mock_response->mock( content => sub { 'foo' } ); $Mock_resp->mock( code => sub { 201 } ); # Validate args passed to request constructor is_deeply $Mock_request->new_args, @expected_args; # Validate request headers is_deeply [ $Mock_req->next_call ], [ 'header', [ 'Accept', 'text/plain' ] ]; # Special User Agent Behaviour $Mock_ua->mock( request => sub { die 'foo' } ); DESCRIPTION
This package arises from duplicating the same code to mock LWP et al in several different modules I've written. This version is very mini- malist, but works for my needs so far. I'm very open to new suggestions and improvements. EXPORTS
The following variables are exported by default: $Mock_ua The mock LWP::UserAgent object - a Test::MockObject object $Mock_req, $Mock_request The mock HTTP::Request object - a Test::MockObject object $Mock_resp, $Mock_response The mock HTTP::Response object - a Test::MockObject object AUTHOR
Luke Closs, "<test-mock-lwp at 5thplane.com>" BUGS
Please report any bugs or feature requests through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Mock-LWP>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORT
You can find documentation for this module with the perldoc command. perldoc Test::Mock::LWP You can also look for information at: * AnnoCPAN: Annotated CPAN documentation <http://annocpan.org/dist/Test-Mock-LWP> * CPAN Ratings <http://cpanratings.perl.org/d/Test-Mock-LWP> * RT: CPAN's request tracker <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Mock-LWP> * Search CPAN <http://search.cpan.org/dist/Test-Mock-LWP> ACKNOWLEDGEMENTS
COPYRIGHT &; LICENSE Copyright 2006 Luke Closs, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.8.8 2007-01-25 Test::Mock::LWP(3pm)

Check Out this Related Man Page

Mock(3pm)						  LogReport's Lire Documentation						 Mock(3pm)

NAME
Lire::Test::Mock - Create mock object SYNOPSIS
use Lire::Report; use Lire::Test::Mock; use Lire::DlfResult; my $mock = new Lire::Test::Mock( 'Lire::Report' ); $mock->set_result( 'timestamp', $time ); $mock->timestamp(); # will return $time $mock->get_calls(); # [ 'timestamp' ] $mock->get_invocation( 'timestamp', 0 ); # [ $mock ] DESCRIPTION
This class makes it easy to defined mock objects. Mock objects are objects which offers the same interface than another object but which do not share its functionality. This makes it easier to test objects which requires fixtures which have lots of dependencies. The mock object can be used to collect information about calls made on the object. Returns value for such method invocation can also be specified. new( $class, 'method' => $result, 'method' => $result ) Creates a new mock object that will wrap $class. Any other keyword arguments will be use to initialize the result of methods call. See set_result() for information on how this works. new_proxy( $class, @constructor_params ) This creates mock object which for the base $class. A proxy mock object will still monitor calls to the object but the real methods will be invoked, unless a result was specified using set_result(). Any remaining parameters will be passed to the new() method which should be defined in the class. new_proxy( $instance ) Makes a Lire::Test::Mock object which is a clone of $instance. is_proxy() Returns whether this mock object will proxy to the real methods when no results was defined for a specific method. get_calls() Returns an array reference containing all the methods called on the object. invocation_count( $method ) Returns the number of time $method was called. get_invocation( $method, $index ) Returns the parameter that were given when method $method was called. set_result( method => $result, ... ) This assign the result $result to $method. If $result is a code reference, it will be invoked with the same argument than the method to compute the result. USING MOCK FACTORIES
Sometime, it is not possible to instatiate a proxy or mock object during fixture setup. This will usually happen when the object which we want to track access to is instantiated by the method under test. In these cases, one can use the set_mock_factory() class method to change the factory method to one that will return a proxy instance instead of a real instance. One should call reset_factories() during tear_down() so that the real factory method become directly accessible once again. set_mock_factory( $class, %results ) Make the new() method of package $class returns proxy Lire::Test::Mock instance. The created instances will be accessible through the mock_instances() method. Any other argument will be passed to the set_result() method when the mock instance is created. mock_instances( $class ) Returns an array reference containing all the instance that were created by the installed mock factory in $class. This method will throw an exception if now mock factory was installed for class $class. reset_factories() Removes all mock factories that were set up using set_mock_factory(). SEE ALSO
Test::Unit::TestCase(3pm) VERSION
$Id: Mock.pm,v 1.5 2006/07/23 13:16:32 vanbaal Exp $ AUTHORS
Francis J. Lacoste <flacoste@logreport.org> COPYRIGHT
Copyright (C) 2004 Stichting LogReport Foundation LogReport@LogReport.org This file is part of Lire. Lire is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html. Lire 2.1.1 2006-07-23 Mock(3pm)
Man Page