MockLDAP.pm 1.04 KB
Newer Older
IKEDA Soji's avatar
IKEDA Soji committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4

package Sympa::Test::MockLDAP;

use strict;
use warnings;
use Test::Net::LDAP::Util qw(ldap_mockify);

use Sympa::DatabaseDriver::LDAP;

sub build {
    my @entries = @_;

    no warnings qw(redefine);
    *Sympa::DatabaseDriver::LDAP::_connect = sub {
        my $ldap;
        ldap_mockify {
            $ldap = Net::LDAP->new;

            foreach my $entry (@entries) {
                $ldap->add(@$entry);
            }
        };
        $ldap;
    };
}

1;
__END__

=encoding UTF-8

=head1 NAME

Sympa::Test::MockLDAP - Mocking LDAP directory

=head1 DESCRIPTION

L<Sympa::Test::MockLDAP> mocks LDAP directory on memory so that it will be
used in unit tests.

=head2 Functions

=over

=item build ( entries... )

Builds mocked directory on memory.

I<entries...> is a list of arrayref to arguments fed to add().

=back

=head1 SEE ALSO

L<Sympa::DatabaseDriver::LDAP>,
L<Sympa::DataSource::LDAP>,
L<Sympa::DataSource::LDAP2>.

=head1 HISTORY

L<Sympa::Test::MockLDAP> appeared on Sympa 6.2.55b.

=cut