PrePAN

Sign in to PrePAN

Test::DeepMock Base package for mock factories

Good

Synopsis

Create your factory of mocks:

    package My::Factory;
    use Test::DeepMock ();

    our @ISA = qw( Test::DeepMock );
    our @CONFIG = {
        'My::Package' => {
            source => 'package My::Package; 1;'
        },
        'My::Another::Package' => {
            file_handle => $FH
        },
        'My::Package::From::File' => {
            path => '/some/path/to/mock'
        },
        default => sub {
            my ($class, $package_name) = @_;
            #returns scalar with source of package or file handle
            #return undef to interrupt mocking
        },
    };

In the test: import packages that you want to mock from your factory:

    use My::Factory qw(
        My::Package
        My::Another::Package
        My::Package::From::File
        This::Package::Will::Trigger::Default::Subroutine
    );

Description

Test::DeepMock is a abstract mock factory which injects mocks into @INC so whenever your app requires a package - mock will be loaded. Extremely useful for testing old legacy code.

Comments

Please sign up to post a review.