Page 1 of 1
PHPUnit
Posted: Sat Dec 26, 2009 6:21 am
by kaisellgren
I find it irritating that PHPUnit has assertions where the parameter order is "unnatural". Like this one:
Code: Select all
assertEquals(mixed $expected, mixed $actual[, string $message = ''])
Why on earth is the $expected value in the first parameter and the $actual value in the second parameter? It would make so much more sense to have it in the reverse order:
Does anyone else find this "unnatural" order of parameters irritating? In my opinion, comparisons are done by first supplying the actual value:
and not
which is just silly.
Sorry for speaking my mind.

Re: PHPUnit
Posted: Sat Dec 26, 2009 12:53 pm
by Darhazer
First of all, there are programmers that use the
1 == $var
comparision
Their reason for this is that if they miss the second equal sign, they will get parse / fatal error instead of a bug.
I don't like this too.
And finally, a lot of PHP function have un-natural ordering of parameters (there was a discussion about the coding convensions in PHP in the General Discussion forum), why the hell you are expecting a natural ordering from a PHP Library

Re: PHPUnit
Posted: Sat Dec 26, 2009 1:46 pm
by josh
I like having the expected value first. I also write my if statements like this now that I have come to accept that I am fallible. If you want to see horrendous, take a look at... cppunit I think it is, that puts the assertion message as the first parameter (although this too is done for a reason, to encourage people to supply a message).
I think having the expected value first makes sense, if you were describing a "system" like the universe, you would first write down the "laws" of this system, the invariants, then *after* that you would do an experiment to test it. So for me writing the expected value first is just an evolution of "test first" development, I like writing the expected value first because I focus on what I am verifying, not how to verify it.
I know simpletest and phpunit do it backwards, which is kind of a pain. It is difficult (although not impossible) to craft a regex that will rewrite your tests for you though.
I like to assign actual & expected to variables named $actual, and $expected... this way it is easier to change with a regex later on if needed.
Lately, I have been looking at FIT which amazes me
http://www.artima.com/weblogs/viewpost.jsp?thread=67373
Re: PHPUnit
Posted: Sat Dec 26, 2009 3:21 pm
by kaisellgren
josh wrote:It is difficult (although not impossible) to craft a regex that will rewrite your tests for you though.
I don't think it's so much of a problem for me really
Seriously, it's like eating a bread where the cheese is below the ham...

you know?
Re: PHPUnit
Posted: Sat Dec 26, 2009 3:47 pm
by josh
Unrelated note - I eat my hamburgers (keep in mind where i live) upside down. Reason - the top bun is thick, the bottom is thin. The juices make the bottom bun soggy.
The problem with reversing argument order is difficult no matter who you are (unless you use temp variables as I described), for me I could only get 90% of my statements switched, the rest I had to do by hand.