RSS ? Recent Blog Posts

Blogs ยป Archive for August 13th, 2007

Nihilism, accessibility, and the preponderence of amazing co-incidences

by James Edwards

I was feeling pretty nihilistic this morning.

Overwhelmed by having to navigate the dirty waters of capitalism trying to do what I feel is right. Not exactly cheered by the possibility of serious health ramifications from more than 20 years as a heavy smoker. Miserable about how long I’ve been single. Generally lacking in inspiration to see me through another day.

Then to read Molly’s recent post about the state of our industry and community, I became even more despondent, as I remembered how the microformats community and WHATWG are behaving like cabals in their self-interested refusal to acknowledge the accessibility issues with that they’re doing; and how so many of their leading lights are utterly refusing to accept this.

By mid-morning I had my head in my hands, sighing, there’s absolutely no point to anything.

The preponderence of amazing co-incidences

Do you ever find yourself amazed by co-incidence? How several things can come together all at once, in a way that so profoundly resonates, it seems like it must mean something more, that it can’t be just a co-incidence? And have you felt, at times, like this happens so frequently that co-incidence no longer seems like an adequate explanation; that perhaps, it indicates …

 

pTest: PHP Unit Tester in 9 Lines Of Code

by Paul Annesley

I was recently working on a command line PHP tool, and didn’t have easy access to our normal PHP unit testing framework built around SimpleTest. After a few lines of non-test-driven-development, I started to freak out a bit - I guess I’ve fallen for the view that if code doesn’t have tests, it’s broken.

I didn’t need support for mock objects or complicated assertions - just a bare basic assertTrue() would do the trick. So, I present “pTest”, in 9 lines of code:

/**
* pTest - PHP Unit Tester
* @param mixed $test Condition to test, evaluated as boolean
* @param string $message Descriptive message to output upon test
*/
function assertTrue($test, $message)
{
static $count;
if (!isset($count)) $count = array(’pass’=>0, ‘fail’=>0, ‘total’=>0);

$mode = $test ? ‘pass’ : ‘fail’;
printf(”%s: %s (%d of %d tests run so far have %sed)\n”,
strtoupper($mode), $message, ++$count[$mode], ++$count[’total’], $mode);
}

Here’s a few contrived test cases to demonstrate:

assertTrue(1 + 1 == 2, ‘one plus one should equal two’);
assertTrue(false, ‘false should be true (this one will fail)’);
assertTrue(!false, ‘false should be false’);

And the sample output:

PASS: one plus one should equal two (1 of 1 tests run so far have passed)
FAIL: false should be true (this one will fail) (1 of …

 

Sponsored Links

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.