We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I recently hit a place where I had to mock out two different interfaces, but wanted to confirm that they got called in the correct order.
use Test2::Mock; my $first = Test2::Mock->new( track => 'WithTimestamps', # or some other interface class => 'AClass', ..., ); my $second = Test2::Mock->new( track => 'WithTimestamps', # or some other interface class => 'AnotherClass', ..., ); ...; # do stuff that calls mocked methods on both classes. my @ordered_calls = sort { $a->{ts} <=> $b->{ts} } ( @{ $first->call_tracking ), @{ $second->call_tracking }, ); like \@ordered_calls, [ { sub_name => ..., args => [ 'AClass' ] }, { sub_name => ..., args => [ 'AnotherClass' ] }, { sub_name => ..., args => [ 'AClass' ] }, ..., ];
The text was updated successfully, but these errors were encountered:
Thinking more on this, I don't actually need the timestamp, perhaps a more flexible solution would be a callback:
my @call_tracking; my $mock1 = Test2::Mock->new( track => sub { push @call_tracking, $_[0] }, ... ); my $mock2 = Test2::Mock->new( track => sub { push @call_tracking, $_[0] }, ... ); ...;
If $_[0] was the ref that was going to be added to call_tracking, someone actually wanting a timestamp could add it themselves.
$_[0]
call_tracking
my $mock = Test2::Mock->new( trace => sub { $_[0]->{ts} = gettimefday }, ... );
Sorry, something went wrong.
No branches or pull requests
I recently hit a place where I had to mock out two different interfaces, but wanted to confirm that they got called in the correct order.
The text was updated successfully, but these errors were encountered: