Skip Menu |

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

Report information
The Basics
Id: 15446
Status: resolved
Worked: 35 min
Priority: 0/
Queue: Test-MockObject

People
Owner: chromatic [...] cpan.org
Requestors: PM [...] blinck.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.01
Fixed in: (no value)



Subject: isa() is broken
The isa() method of mock objects is broken; it doesn't return true when testing for a data type like "HASH": use Test::More tests => 1; use Test::MockObject::Extends; # fake that Foo is loaded $INC{"Foo.pm"} = "./Foo.pm"; # create object $obj = bless {}, "Foo"; # wrap in mock object Test::MockObject::Extends->new($obj); # test if the mock object is still a hash isa_ok($obj, "HASH", $obj);
Test::MockObject always uses the method call, these being objects. If you really want to check the type of a reference, use Scalar::Util::reftype() instead. UNIVERSAL::isa() only returns true for unblessed references when used as a function, but I consider this a broken design and choose not to support it. (I also consider it a bug that Test::More, at least as of version 0.62, uses UNIVERSAL::isa() as a function in this case and not reftype().)
From: PM [...] blinck.com
Okay, but without using Test::More::isa_ok(), the following script still fails the third and fourth test: use Test::More tests => 4; use Test::MockObject::Extends; # fake that Foo is loaded $INC{"Foo.pm"} = "./Foo.pm"; # create object $obj = bless {}, "Foo"; # test if the object is a reference to a hash ok($obj->isa("HASH"), "The object isa HASH"); ok(UNIVERSAL::isa($obj, "HASH"), "...also if UNIVERSAL::isa() is called as a function"); # wrap in mock object Test::MockObject::Extends->new($obj); # test if the mock object is still a reference to a hash ok($obj->isa("HASH"), "The extended object isa HASH"); ok(UNIVERSAL::isa($obj, "HASH"), "...also if UNIVERSAL::isa() is called as a function"); Of course, I could use Scalar::Util::reftype(), but why import an extra module, if UNIVERSAL::isa() can tell me the same? The point is that if I extend my object with Test::MockObject::Extends, the behaviour of my object's isa() method changes.
I've added your example to the test suite as of 1.03 and made it pass. Thanks for the report.