Net::DBus::Test::MockObject - a 'mock' object for use in test suites
use Net::DBus; use Net::DBus::Test::MockObject; my $bus = Net::DBus->test # Lets fake presence of HAL... # First we need to define the service my $service = $bus->export_service("org.freedesktop.Hal"); # Then create a mock object my $object = Net::DBus::Test::MockObject->new($service, "/org/freedesktop/Hal/Manager"); # Fake the 'GetAllDevices' method $object->seed_action("org.freedesktop.Hal.Manager", "GetAllDevices", reply => { return => [ "/org/freedesktop/Hal/devices/computer_i8042_Aux_Port", "/org/freedesktop/Hal/devices/computer_i8042_Aux_Port_logicaldev_input", "/org/freedesktop/Hal/devices/computer_i8042_Kbd_Port", "/org/freedesktop/Hal/devices/computer_i8042_Kbd_Port_logicaldev_input" ], }); # Now can test any class which calls out to 'GetAllDevices' in HAL ....test stuff....
This provides an alternate for Net::DBus::Object to enable bus objects to be quickly mocked up, thus facilitating creation of unit tests for services which may need to call out to objects provided by 3rd party services on the bus. It is typically used as a companion to the Net::DBus::MockBus object, to enable complex services to be tested without actually starting a real bus.
!!!!! WARNING !!!
This object & its APIs should be considered very experimental at this point in time, and no guarentees about future API compatability are provided what-so-ever. Comments & suggestions on how to evolve this framework are, however, welcome & encouraged.
my $object = Net::DBus::Test::MockObject->new($service, $path, $interface);
Create a new mock object, attaching to the service defined by the $service parameter. This would be an instance of the Net::DBus::Service object. The $path parameter defines the object path at which to attach this mock object, and $interface defines the interface it will support.
$service
$path
$interface
It doesn't completely replicate the API of Net::DBus::Binding::Object, merely enough to make the high level bindings work in a test scenario.
Net::DBus, Net::DBus::Object, Net::DBus::Test::MockConnection, http://www.mockobjects.com/Faq.html
Copyright 2005 Daniel Berrange <dan@berrange.com>
2 POD Errors
The following errors were encountered while parsing the POD:
You can't have =items (as at line 90) unless the first thing after the =over is an =item
You forgot a '=back' before '=head1'
To install Net::DBus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::DBus
CPAN shell
perl -MCPAN -e shell install Net::DBus
For more information on module installation, please visit the detailed CPAN module installation guide.