testing return type of getters?

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: testing return type of getters?

Post by Chris Corbyn »

Jenk wrote:Which is implicitly tested by calling isAuthenticated(). I wouldn't test for the interface then.
Not really. Not if this object must be passed to function (that you didn't write, such as the Authentication layer in ZF) that has a type-hint on it. You're not going to start editing ZF to remove its type-hints, so you make sure your own code is returning the appropriate type. Having the correct methods does not make it the correct type.

However, I got confused and thought we were talking more about primitive types. For example, 0, null, "" and false all act the same in boolean context. But sometimes the return type is very important (such as in strpos() or readdir()). In those cases you definitely should be checking the type.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: testing return type of getters?

Post by Jenk »

I completely forgot about primitives. :) (Have been using Smalltalk for too long now!) In that instance I would agree, because of the way PHP handles primitive types with operators. is_string() etc. or (string)$foo === $foo.

RE: Type hints.. that's one of the draw backs of using Type declarations.
Post Reply