PHPUnit

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

PHPUnit

Post 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:

Code: Select all

assertEquals($actual, $expected)
Does anyone else find this "unnatural" order of parameters irritating? In my opinion, comparisons are done by first supplying the actual value:

Code: Select all

if ($actual == 5)
and not

Code: Select all

if (1 == $id)
which is just silly. :|

Sorry for speaking my mind. :)
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: PHPUnit

Post 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 :mrgreen:
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PHPUnit

Post 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
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: PHPUnit

Post 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 :P

Seriously, it's like eating a bread where the cheese is below the ham... :roll: you know?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PHPUnit

Post 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.
Post Reply