in reply to Testing Wrapped LDAP Classes

There are a few mocking distributions on the CPAN, but I'll show an example using my Mock::Sub. You can mock out subs, then tell it to do something (side_effect()), or return something (return_value()). Instead of using a method to set them, you can also specify them in the constructor if you choose (then remove/modify them with the methods later):

use warnings; use strict; use lib '.'; use Mock::Sub; use Test::More; use Utils::Ldap::CompanyLdap; my $m = Mock::Sub->new; my $ldap = Utils::Ldap::CompanyLdap->new; my $mocked_sub = $m->mock( 'Utils::Ldap::CompanyLdap::searchGetEntries' ); $mocked_sub->return_value(qw(steve mike dave)); read_users(); is $mocked_sub->called, 1, "searchGetEntries() called ok"; sub read_users { for my $entry ($ldap->searchGetEntries()){ print "$entry\n"; } } done_testing();


steve mike dave ok 1 - searchGetEntries() called ok 1..1