Skip Menu |

This queue is for tickets about the Test-MockObject CPAN distribution.

Report information
The Basics
Id: 70274
Status: open
Priority: 0/
Queue: Test-MockObject

People
Owner: Nobody in particular
Requestors: alexey [...] infoxchange.net.au
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 1.06
  • 1.09
  • 1.20110612
Fixed in: (no value)



Subject: Cannot use set_bound to bind to an arrayref
One cannot use set_bound to bind a method to an arrayref, e.g. my $mock = Test::MockObject->new(); my $arrayref = [1, 2, 3]; $mock->set_bound('arrayref', \$arrayref); print Dumper($mock->arrayref); The object behaves as if 'arrayref' method has not been mocked at all (see the attachment for the exact source): Un-mocked method 'arrayref()' called at ./test.pm line 13 The expected result would be: $VAR1 = [ 1, 2, 3 ]; The attached one-line patch fixes the bug (set_bound doesn't know what to do with a reference to a reference). --- Distribution name and version Test-MockObject-1.20110612 Perl version v5.10.1 Operating System vendor and version Linux aluminium 2.6.38-11-generic-pae #48-Ubuntu SMP Fri Jul 29 20:51:21 UTC 2011 i686 i686 i386 GNU/Linux
Subject: set_bound_patch
Download set_bound_patch
application/octet-stream 302b

Message body not shown because it is not plain text.

Subject: test.pm
#!/usr/bin/perl use warnings; use strict; use Test::MockObject; use Data::Dumper; my $mock = Test::MockObject->new(); my $arrayref = [1, 2, 3]; $mock->set_bound('arrayref', \$arrayref); print Dumper($mock->arrayref);
From: dmaestro
On Sun Aug 14 22:32:30 2011, http://koterpillar.myopenid.com/ wrote: Show quoted text
> One cannot use set_bound to bind a method to an arrayref, e.g. > > my $mock = Test::MockObject->new(); > my $arrayref = [1, 2, 3]; > $mock->set_bound('arrayref', \$arrayref); > print Dumper($mock->arrayref); >
The same patch fixes the case of a variable containing a blessed reference. e.g. $self->{override_url} = URI->new('http://localhost:8081'); my $mock = Test::MockObject::Extends->new(WWW::Proxy->new); $mock->set_bound('get_url', \$self->{override_url}) || die "Failed to mock"; Without the patch (and without the 'die' above), $mock->get_url returns the value from the original object's method. The documentation might mention that set_bound returns undef if it can't handle the given reference, and suggest checking the return value as above. Show quoted text
> The object behaves as if 'arrayref' method has not been mocked at all > (see the attachment for the exact source): > > Un-mocked method 'arrayref()' called at ./test.pm line 13 > > The expected result would be: > > $VAR1 = [ > 1, > 2, > 3 > ]; > > The attached one-line patch fixes the bug (set_bound doesn't know what > to do with a reference to a reference). > > --- > Distribution name and version > Test-MockObject-1.20110612 > > Perl version > v5.10.1 > > Operating System vendor and version > Linux aluminium 2.6.38-11-generic-pae #48-Ubuntu SMP Fri Jul 29 20:51:21 > UTC 2011 i686 i686 i386 GNU/Linux

+1 for applying this patch!

-- 
Olivier Mengué - http://perlresume.org/DOLMEN - https://gratipay.com/dolmen/
Le 2011-08-15 04:32:30, http://koterpillar.myopenid.com/ a écrit :
Show quoted text
> The attached one-line patch fixes the bug (set_bound doesn't know what
> to do with a reference to a reference).

I have submitted your patch as a pull request on GitHub:
https://github.com/chromatic/Test-MockObject/pull/12

-- 
Olivier Mengué - http://perlresume.org/DOLMEN - https://gratipay.com/dolmen/