Test-Mockingbird
view release on metacpan or search on metacpan
lib/Test/Mockingbird.pm view on Meta::CPAN
{
## no critic (ProhibitNoStrict)
no strict 'refs';
*{$full_method} = $replacement;
}
my $type = $Test::Mockingbird::TYPE // 'mock';
push @{ $mock_meta{$full_method} }, {
type => $type,
installed_at => (caller)[1] . ' line ' . (caller)[2],
};
}
=head2 unmock($package, $method)
Restores the original method for a mocked method.
Supports two forms:
unmock('My::Module', 'method');
lib/Test/Mockingbird.pm view on Meta::CPAN
no warnings 'redefine';
{
## no critic (ProhibitNoStrict)
no strict 'refs';
*{$full_method} = $wrapper;
}
push @{ $mock_meta{$full_method} }, {
type => 'spy',
installed_at => (caller)[1] . ' line ' . (caller)[2],
};
return sub { @calls };
}
=head2 inject($package, $dependency, $mock_object)
Injects a mock dependency. Supports two forms:
inject('My::Module', 'Dependency', $mock_object);
lib/Test/Mockingbird.pm view on Meta::CPAN
no warnings 'redefine';
{
## no critic (ProhibitNoStrict) # symbolic reference required for injection
no strict 'refs';
*{$full_dependency} = $wrapper;
}
push @{ $mock_meta{$full_dependency} }, {
type => 'inject',
installed_at => (caller)[1] . ' line ' . (caller)[2],
};
}
=head2 restore_all
Restores all mocked methods and injected dependencies.
Called with no arguments, restores everything that has been mocked
in the current test run:
( run in 2.031 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )