Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix circular reference.

Remove a `mock` property from `Expectations`.
  • Loading branch information...
commit c4a0625db5d653b9bf2c8386954350ad9bb13693 1 parent 2b1b5d1
@NetPenguin authored
View
5 lib/Test/EasyMock.pm
@@ -107,7 +107,7 @@ sub create_mock {
return $control->create_mock;
}
-=head2 expect($expectation)
+=head2 expect(<a mock method call>)
Record a method invocation and behavior.
@@ -155,8 +155,7 @@ Set I<die> behavior as as stub to the expectation.
=cut
sub expect {
- my ($expectation) = @_;
- return __delegate(expect => ($expectation->mock, $expectation));
+ return __delegate(expect => @_);
}
=head2 replay($mock [, $mock2 ...])
View
17 lib/Test/EasyMock/Expectation.pm
@@ -8,11 +8,10 @@ Test::EasyMock::Expectation - A expected behavior object.
=cut
use Carp qw(croak);
-use Scalar::Util qw(refaddr);
=head1 CONSTRUCTORS
-=head2 new({mock=>$mock, method=>$method, args=>$args})
+=head2 new(method=>$method, args=>$args})
Create a instance.
@@ -20,23 +19,12 @@ Create a instance.
sub new {
my ($class, $args) = @_;
return bless {
- _mock => $args->{mock},
_method => $args->{method},
_args => $args->{args},
_results => [ { code => sub { return; }, implicit => 1 } ],
}, $class;
}
-=head1 PROPERTIES
-
-=head2 mock - A related mock object.
-
-=cut
-sub mock {
- my ($self) = @_;
- return $self->{_mock};
-}
-
=head1 METHODS
=head2 push_result($code)
@@ -112,8 +100,7 @@ It is tested whether the specified argument matches.
=cut
sub matches {
my ($self, $args) = @_;
- return refaddr($self->{_mock}) == refaddr($args->{mock})
- && $self->{_method} eq $args->{method}
+ return $self->{_method} eq $args->{method}
&& $self->{_args}->matches($args->{args});
}
View
8 lib/Test/EasyMock/MockControl.pm
@@ -10,7 +10,7 @@ Test::EasyMock::MockControl - Control behavior of the mock object.
use Data::Dump qw(pp);
use Data::Util qw(is_instance);
use List::Util qw(first);
-use Scalar::Util qw(blessed refaddr);
+use Scalar::Util qw(blessed);
use Test::Builder;
use Test::EasyMock::ArgumentsMatcher;
use Test::EasyMock::Expectation;
@@ -33,7 +33,7 @@ sub create_control {
=head1 CONSTRUCTORS
-=head2 new($expectation)
+=head2 new([$module|$object])
Create a instance.
@@ -110,13 +110,13 @@ Record the method invocation.
=cut
sub record_method_invocation {
my ($self, $mock, $method, @args) = @_;
- return Test::EasyMock::Expectation->new({
- mock => $mock,
+ my $expectation = Test::EasyMock::Expectation->new({
method => $method,
args => is_instance($args[0], 'Test::EasyMock::ArgumentsMatcher')
? $args[0]
: Test::EasyMock::ArgumentsMatcher->new(\@args),
});
+ return ($mock, $expectation);
}
=head2 find_expectation($args)
Please sign in to comment.
Something went wrong with that request. Please try again.