Test::Mock::One - Mock the world with one object
version 0.001
use Test::Mock::One; my $mock = Test::Mock::One->new( foo => 'return value', bar => 1, hashref => \{ foo => bar }, arrayref => \[ foo => bar ], code => sub { return your_special_function }, # Override various things X-Mock-Strict => 1, X-Mock-Stringify => sub { return 'foo' }, X-Mock-ISA => sub { return 'foo' }, ); $mock->foo; # 'return value' $mock->bar; # 1 $mock->hashref; # { foo => bar} $mock->arrayref; # [ foo, bar ] $mock->code; # executes your_special_function
Be able to mock many things with little code by using AUTOLOAD.
Ways to override specific behaviours
Boolean value. Undefined attributes will not be mocked and calling them makes us die.
Mock the ISA into the given class. Supported ways to mock the ISA:
X-Mock-ISA => 'Some::Pkg', X-Mock-ISA => qr/Some::Pkg/, X-Mock-ISA => [qw(Some::Pkg Other::Pkg)], X-Mock-ISA => sub { return 0 }, X-Mock-ISA => undef,
Tell us how to stringify the object
X-Mock-Stringify => 'My custom string', X-Mock-Stringify => sub { return "foo" },
Override the ISA from the object
Wesley Schwengle <wesleys@opperschaap.net>
This software is Copyright (c) 2017 by Wesley Schwengle.
This is free software, licensed under:
The (three-clause) BSD License
To install Test::Mock::One, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Mock::One
CPAN shell
perl -MCPAN -e shell install Test::Mock::One
For more information on module installation, please visit the detailed CPAN module installation guide.