Page 2 of 2

Re: testing return type of getters?

Posted: Wed Mar 18, 2009 8:26 pm
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.

Re: testing return type of getters?

Posted: Thu Mar 19, 2009 6:24 am
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.