After an earlier question (Mocking Class::DBI stringification) about Test::MockObject, I pushed on a bit and then encountered (to me) some extremely befuddling behavior.
In the code below, after I reset a variable, $id='apple', the mocking breaks.
Why?
Thanks --
use strict; use warnings FATAL => 'all'; use Test::MockObject; use Test::More tests => 7; use Data::Dumper; use UNIVERSAL qw (isa can); package main; my $id = -1; sub return_id {return $id;} package MockFoo; # ! THIS IS THE *WRONG* WAY TO STRINGIFY A T:MO ?? use base qw(Test::MockObject); use overload '""' => \&::return_id; package main; my $c = MockFoo->new; $c->set_isa('Foo'); $c->mock('id', \&::return_id); is($id, -1, 'the bound scalar'); isa_ok($c, 'Foo'); ok ($c->isa('Foo'), 'and c isa foo, maybe'); ok(!isa($c,'Foo'), 'THIS SHOULD WORK (IMHO) but DOESNT, T:MO DOESNT FO +OL UNIVERSAL'); ok(!can($c, 'id'), 'THIS SHOULD WORK (IMHO) but DOESNT, T:MO DOESNT FO +OL UNIVERSAL'); is($c->id, -1, 'mocked accessor'); is($c->id, -1, 'mocked accessor repeated'); is('' . $c, -1, 'stringify'); $id='apple'; is($c->id, 'apple', 'apple: mocked accessor'); is('' . $c, 'apple', 'apple: stringify');
In reply to Test::MockObject subclassing befuddlement by water
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |