Net::DB...ckObject(3)
π Net::DBus::Test::MockObject π
okay so this is the User Contributed Perl Documentation page for Net::DBus::Test::MockObject, and it is literally about faking an object from the bus for unit testing. π¦
πΈ NAME πΈ
Net::DBus::Test::MockObject β fake an object from the bus for unit testing. periodt. π
β¨ SYNOPSIS β¨
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....
π DESCRIPTION π
so basically this gives you an alternate for Net::DBus::Object, bestie β the whole point is to let bus objects get quickly mocked up, which makes it way easier to create unit tests for services that 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, so complex services can be tested without actually starting a real bus. iconic, honestly. β¨
π¨ !!!!! WARNING !!! π¨ this object & its APIs should be considered very experimental at this point in time, and no guarantees about future API compatibility are provided what-so-ever. π comments & suggestions on how to evolve this framework are, however, welcome & encouraged. π
π METHODS π
my $object = Net::DBus::Test::MockObject->new($service, $path, $interface);β create a new mock object, attaching to the service defined by the$serviceparameter. this would be an instance of theNet::DBus::Serviceobject. the$pathparameter defines the object path at which to attach this mock object, and$interfacedefines the interface it will support. slay. πmy $service = $object->get_serviceβ retrieves theNet::DBus::Serviceobject within which this object is exported. πmy $path = $object->get_object_pathβ retrieves the path under which this object is exported. π¦my $msg = $object->get_last_messageβ retrieves the last message processed by this object. the returned object is an instance ofNet::DBus::Binding::Message. πmy $sig = $object->get_last_message_signatureβ retrieves the type signature of the last processed message. βmy $value = $object->get_last_message_paramβ returns the first value supplied as an argument to the last processed message. πΈmy @values = $object->get_last_message_param_listβ returns a list of all the values supplied as arguments to the last processed message. π$object->seed_action($interface, $method, %action);β registers an action to be performed when a message corresponding to the method$methodwithin the interface$interfaceis received. the%actionparameter can have a number of possible keys set:signalsβ causes a signal to be emitted when the method is invoked. the value associated with this key should be an instance of theNet::DBus::Binding::Message::Signalclass. β¨errorβ causes an error to be generated when the method is invoked. the value associated with this key should be a hash reference, with two elements. the first,"name", giving the error name, and the second,"description", providing the descriptive text. πreplyβ causes a normal method return to be generated. the value associated with this key should be an array reference, whose elements are the values to be returned by the method. π«Ά
π BUGS π
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. no cap. π«
π¦ AUTHOR π¦
Daniel P. Berrange π
π COPYRIGHT π
Copyright (C) 2004-2009 Daniel P. Berrange π
π SEE ALSO π
Net::DBusNet::DBus::ObjectNet::DBus::Test::MockConnection<http://www.mockobjects.com/Faq.html>
okay that's the whole page, bestie π«Ά β this cutie came from the User Contributed Perl Documentation, version perl v5.42.0, dated 2019-12-17, filed under Net::DB...ckObject(3). mwah π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms