An open API service indexing awesome lists of open source software.

https://github.com/nigelhorne/test-mockingbird

Advanced mocking library for Perl with support for dependency injection and spies
https://github.com/nigelhorne/test-mockingbird

cpan cpan-module perl perl5

Last synced: 9 months ago
JSON representation

Advanced mocking library for Perl with support for dependency injection and spies

Awesome Lists containing this project

README

          

# NAME

Test::Mockingbird - Advanced mocking library for Perl with support for dependency injection and spies

# VERSION

Version 0.02

# SYNOPSIS

use Test::Mockingbird;

# Mocking
Test::Mockingbird::mock('My::Module', 'method', sub { return 'mocked!' });

# Spying
my $spy = Test::Mockingbird::spy('My::Module', 'method');
My::Module::method('arg1', 'arg2');
my @calls = $spy->(); # Get captured calls

# Dependency Injection
Test::Mockingbird::inject('My::Module', 'Dependency', $mock_object);

# Unmocking
Test::Mockingbird::unmock('My::Module', 'method');

# Restore everything
Test::Mockingbird::restore_all();

# DESCRIPTION

Test::Mockingbird provides powerful mocking, spying, and dependency injection capabilities to streamline testing in Perl.

# METHODS

## mock($package, $method, $replacement)

Mocks a method in the specified package.

## unmock($package, $method)

Restores the original method for a mocked method.

## spy($package, $method)

Spies on a method, tracking calls and arguments.

## inject($package, $dependency, $mock\_object)

Injects a mock object for a dependency.

## restore\_all()

Restores all mocked methods and dependencies to their original state.

# SUPPORT

This module is provided as-is without any warranty.

Please report any bugs or feature requests to `bug-test-mockingbird at rt.cpan.org`,
or through the web interface at
[http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Mockingbird](http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Mockingbird).
I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

You can find documentation for this module with the perldoc command.

perldoc Test::Mockingbird