PHPT_Ensure v0.1alpha and PHPT_Core v0.1.1alpha Released

Author’s note: I’m pretty doped up right now on some various cough medicines to try and kick this cold before everyone comes over to my house on Thanksgiving, so I can’t guarantee the coherence of this post…

I woke up this morning a bit before 5 and couldn’t go back to sleep. I decided to try to get some of the busy work on a new package, PHPT_Ensure finished up. I hinted at it a few weeks ago, but now it’s ready for use, albeit a bit limited.

To install it, you’ll need to update to PHPT_Core v0.1.1alpha (a quick pear upgrade phpt/PHPT_Core-alpha should get it taken care of). Once that’s installed, just do your normal pear install phpt/PHPT_Ensure to get it installed. This new package adds an ensure section and the ability to handle assertions with a much cleaner API. A test might look something like this:

Ensure string is properly set

$string = 'Hello World!';
ensure($string)->equals('Hello World!');


And you’re off. No more assert() function calls necessary. It still needs some tweaking, but it’s a usable 0.1 alpha package.

One area that I’m looking for input on is how to show the differences between two arrays. One option is to do a var_export() of each array and and then display a unified diff of the two. This seems rather low-tech to me, but I’m not actually sure how to approach a change. The only decent thought I’ve had so far is to do something along the lines of:

value is expected to be equal to an array
values expected[0][1] and actual[0][1] were not equal at character 0

That assumes that the equals was based a multi-dimensional array where [0][1] => ‘foobar’ and the actual value was [0][1] => ‘barfoo’ or some other string not equal to foobar. This is also an issue with comparing objects. Is a simple failed expectation message enough, or does it need something more verbose? And more verbose as in creating a Reflection and figuring out exactly where things were different, or is something else better?

There’s still a lot of issues to be worked out before it gets to a 1.0, but hopefully it’ll provide you with something useful in the meantime. As always, please report any issues you find.