Is this because UNIVERSAL is the root of the object hierarchy, and thus can't be fooled?use strict; use warnings FATAL => 'all'; use Test::MockObject; use Test::More tests => 6; my $c = Test::MockObject->new; $c->set_isa('Foo'); $c->mock('id', sub {return -1;}); ok($c->can('id'), "c can id (via 'can' method)"); ok($c->isa('Foo'), "c isa Foo (via 'isa' method)"); isa_ok($c, 'Foo', 'c isa_ok Foo'); is($c->id, -1, 'mocked accessor'); # FAILS! ok(UNIVERSAL::isa($c, 'Foo'), 'c isa Foo (via UNVERSAL::isa)'); # FAILS! ok(UNIVERSAL::can($c, 'id'), 'c can id (via UNIVERSAL::can');
If so, it would seem that methods which need to check the type of their arguments (asserting if the wrong param type sent, for example), should use $self->isa rather than UNIVERSAL::isa to do so, as otherwise you can't use Mock Objects to test the methods.
(In contrast, this nice perl OO style guide suggests UNIVERSAL:: over the method call approach. Which I think isn't great advice if you'll be testing with Test::MockObject.)
This isn't a SOPW post per se, but I end with the following question: are the observations above correct, or did I misuse UNIVERSAL?
Thanks!
Retitled by davido from 'Class::MockObject doesn't fool UNIVERSAL'.
In reply to Test::MockObject doesn't fool UNIVERSAL by water
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |