1Net::DBus::Test::MockObUjseecrt(C3o)ntributed Perl DocumNeentt:a:tDiBouns::Test::MockObject(3)
2
3
4

NAME

6       Net::DBus::Test::MockObject - Fake an object from the bus for unit
7       testing
8

SYNOPSIS

10         use Net::DBus;
11         use Net::DBus::Test::MockObject;
12
13         my $bus = Net::DBus->test
14
15         # Lets fake presence of HAL...
16
17         # First we need to define the service
18         my $service = $bus->export_service("org.freedesktop.Hal");
19
20         # Then create a mock object
21         my $object = Net::DBus::Test::MockObject->new($service,
22                                                       "/org/freedesktop/Hal/Manager");
23
24         # Fake the 'GetAllDevices' method
25         $object->seed_action("org.freedesktop.Hal.Manager",
26                              "GetAllDevices",
27                              reply => {
28                                return => [ "/org/freedesktop/Hal/devices/computer_i8042_Aux_Port",
29                                            "/org/freedesktop/Hal/devices/computer_i8042_Aux_Port_logicaldev_input",
30                                            "/org/freedesktop/Hal/devices/computer_i8042_Kbd_Port",
31                                            "/org/freedesktop/Hal/devices/computer_i8042_Kbd_Port_logicaldev_input"
32                                ],
33                              });
34
35
36         # Now can test any class which calls out to 'GetAllDevices' in HAL
37         ....test stuff....
38

DESCRIPTION

40       This provides an alternate for Net::DBus::Object to enable bus objects
41       to be quickly mocked up, thus facilitating creation of unit tests for
42       services which may need to call out to objects provided by 3rd party
43       services on the bus. It is typically used as a companion to the
44       Net::DBus::MockBus object, to enable complex services to be tested
45       without actually starting a real bus.
46
47       !!!!! WARNING !!!
48
49       This object & its APIs should be considered very experimental at this
50       point in time, and no guarantees about future API compatibility are
51       provided what-so-ever. Comments & suggestions on how to evolve this
52       framework are, however, welcome & encouraged.
53

METHODS

55       my $object = Net::DBus::Test::MockObject->new($service, $path,
56       $interface);
57           Create a new mock object, attaching to the service defined by the
58           $service parameter. This would be an instance of the
59           Net::DBus::Service object. The $path parameter defines the object
60           path at which to attach this mock object, and $interface defines
61           the interface it will support.
62
63       my $service = $object->get_service
64           Retrieves the Net::DBus::Service object within which this object is
65           exported.
66
67       my $path = $object->get_object_path
68           Retrieves the path under which this object is exported
69
70       my $msg = $object->get_last_message
71           Retrieves the last message processed by this object. The returned
72           object is an instance of Net::DBus::Binding::Message
73
74       my $sig = $object->get_last_message_signature
75           Retrieves the type signature of the last processed message.
76
77       my $value = $object->get_last_message_param
78           Returns the first value supplied as an argument to the last
79           processed message.
80
81       my @values = $object->get_last_message_param_list
82           Returns a list of all the values supplied as arguments to the last
83           processed message.
84
85       $object->seed_action($interface, $method, %action);
86           Registers an action to be performed when a message corresponding to
87           the method $method within the interface $interface is received. The
88           %action parameter can have a number of possible keys set:
89
90           signals
91               Causes a signal to be emitted when the method is invoked. The
92               value associated with this key should be an instance of the
93               Net::DBus::Binding::Message::Signal class.
94
95           error
96               Causes an error to be generated when the method is invoked. The
97               value associated with this key should be a hash reference, with
98               two elements. The first, "name", giving the error name, and the
99               second, "description", providing the descriptive text.
100
101           reply
102               Causes a normal method return to be generated. The value
103               associated with this key should be an array reference, whose
104               elements are the values to be returned by the method.
105

BUGS

107       It doesn't completely replicate the API of Net::DBus::Binding::Object,
108       merely enough to make the high level bindings work in a test scenario.
109

AUTHOR

111       Daniel P. Berrange
112
114       Copyright (C) 2004-2009 Daniel P. Berrange
115

SEE ALSO

117       Net::DBus, Net::DBus::Object, Net::DBus::Test::MockConnection,
118       <http://www.mockobjects.com/Faq.html>
119
120
121
122perl v5.36.0                      2022-07-22    Net::DBus::Test::MockObject(3)
Impressum