Writing phpt files for PEAR and profit

I’ve been programming PHP now for, oh, almost a decade and I’ve been a contributor to PEAR for about four years now. It took me this long to finally get to the point that I think writing unit tests, in some form, is a good idea. I jumped on the OOP bandwagon about 6 years ago and drank the MVC koolaid about 4 years ago. As of a few weeks ago, I’ve jumped on the phpt bandwagon. I’m not going to cover the basics, because they’re well covered in a few different places around the web, but I am going to cover some of the nuances I’ve learned in the last few weeks.First off, you can run phpt files using the PEAR command line utility. I’ve been creating a tests directory and putting all of my phpt files in there. I normally name them 000-class-method.phpt and then increment the sequence number at the front for each test by 5 so I can do a decent job of predicting how tests run. Once you have a few tests you can run your tests in two different manners from the command line:

  1. pear run-tests
  2. pear run-tests 000-class-method.phpt

When you run your tests you’ll get results of which tests passed, which failed, if any of them were skipped and the reason why they were skipped, and files for debugging. If 000-class-method.phpt fails, there are a few files that will be of interest to you:

  • 000-class-method.php is the actual PHP file ran, which is found in the --FILE-- portion of your phpt file.
  • 000-class-method.outis what was actually output by the PHP file ran from the --FILE-- portion of your phpt file.
  • 000-class-method.exp is what the test expected the output of 000-class-method.php to be, which is found in the --EXPECT-- portion of your phpt file.

You pretty much have everything you need to debug why a test failed. I normally diff the exp and out files and then debug the test (or my code, which is usually the case) using the php file.

Another great thing about phpt files is that you can use a cgi PHP binary to debug actual GET requests (phpt supports spoofing $_GET, $_POST and $_COOKIE using the cgi binary). This lets you create tests like the following:

--TEST--
Test a GET request
--GET--
foo=bar&baz=foo
--FILE--
<?php
echo $_GET['bar'] . "\n";
echo $_GET['baz'] . "\n";

?>
--EXPECT--
bar
foo

This test should pass without incident. The only catch is that you need to specify your cgi binary path using the --cgi argument when you run the tests (e.g. pear run-tests --cgi=/path/to/php-cgi).

Overall, I’m pretty happy with my newfound testing experiences. My only complaint is that phpt files don’t support spoofing of $_SESSION natively. A small complaint to be sure.

My first Digg code goes live

So if you’re interested in seeing what I’ve been doing for Digg lately, you can now go to the site, log in and send invites to your friends. You’ve actually always been able to do this, but now you’re able to keep track of how many friends you’ve invited, those friend invites will be announced to the world on the homepage and you’ll automagically be added to the invitee’s friends list.

Once you’ve invited a friend, the friend needs to register and digg at least three stories before they count as a referral. At that point a little note is posted to the frontpage announcing your invite and your friend referral count in your user profile goes up. I, of course, invite all of you to join.

I’ve also been working on other magical doings, but I can’t talk about those quite yet. I hope to talk more about that work after it goes live as well.

Bill of Non-Rights

A family member of mine sent me one of those ultra-patriotic/conservative mail forwards that was, essentially, a “Bill of Non-Rights” that included a bunch of “get off your lazy ass and get a job” language and two things, in particular, I find laughable.

This is an English speaking country. We don’t care where you are from, English is our language. Learn it or go back to wherever you came from!

I submit that this country, from the very beginning, was multi-lingual and multi-national. I know for a fact that my ancestors didn’t speak English when they arrived, rather they spoke German and French. America is not, nor has it ever been an English-only speaking country. In fact, about 28 million Americans over the age of 5 speak Spanish at home. There’s nothing wrong with being bilingual. In fact, that’s pretty cool if you ask me.

You do not have the right to change our country’s history or heritage. This country was founded on the belief in one true God. And yet, you are given the freedom to believe in any religion, any faith, or no faith at all; with no fear of persecution. The phrase IN GOD WE TRUST is part of our heritage and history, and if you are uncomfortable with it, TOUGH!

Where to start? How about with the fact that “In God We Trust” wasn’t added to coins in America until the Civil War. Also, there’s that pesky fact that “One nation … under God” wasn’t added to the Pledge of Allegiance until 1954.

Now, please, let’s stop with the preposterous assertions that we’ve always been an English-only Christian nation. The truth is we’ve always been a multilingual multicolored nation and it’s only getting moreso. California, for instance, became the first state in the union in 2000 to be a minority-majority population (meaning there’s more of “them” than “us” if that’s how you think).

Maybe a better solution is to follow the Bill of Rights as they are, which guarantee the right to speak any language you want and practice any religion you want. And, guess what, it’s actually been like that from the beginning.

Term 'Civil War' is inadequate term for Iraq

A new Pentagon report said some elements of the war in Iraq fit the definition of civil war, but the term “does not adequately capture the complexity of the conflict.

What I read from this is that the situation in Iraq is much worse than a simple civil war. In fact, with the meddling ways of Iran and Syria it probably is much worse than a simple civil war. Throw in a little religion and a thousand years of bikering and you’ve got yourself something that the term ‘civil war’ “does not adequately capture the complexity of …”.

The problem, of course, it’s that it’s our complex conflict. We’re the ones that messed everything up and we’ve got to at least try to fix the mess, which is why I don’t support an immediate troop pullout. What I do support:

  1. Actively engage Syria and Iraq on all fronts.
  2. Add strict deadlines to a phased reduction of forces so the Iraqis are forced to step up and start policing their own state.
  3. If all else fails, bribe Turkey into letting us create three states out of Iraq. If you didn’t already know, Turkey is vehemently against an independent Kurdistan.

God, please kill my daughters

The state of Texas is up in arms about the fact that the governor had the nerve to require that the HPV vaccine be given to all 6th grade girls. The nerve! A vaccine that prevents cancer?! Given to my daughters?! Blasphemy!

Their reasoning? It promotes promiscuity. Please. How about you do what every other self-respecting parent does when faced with an uncomfortable situation with their children: lie. Tell them it’s a vaccine that prevents cancer and leave it at that. How about having a responsible conversation about safe sex instead of pretending that your daughter is different and won’t have premarital sex.

I’ll let you in on a little secret; 9 out of 10 Americans practice premarital sex. That study includes women from the 1940’s as well so you older folks can’t get all holy on us younger people.

My vote is every girl is vaccinated and we cross our fingers that cervical cancer and HPV is abolished in the same manner that polio was for our parents.

FBI snooping did not follow "rules"

To absolutely nobody’s surprise the Justice Department’s inspector found the FBI to be guilty of “serious misuse” of the power’s granted to it via the PATRIOT Act to secretly request a person’s financial, banking and phone records. What I find laughable is that the audit says that there were no indications that any of the activity “constituted criminal misconduct.”

I find this laughable because these rules are actually laws governing how the FBI can use these powers. They’re not guidelines; they’re law. Normally, when a person or entity doesn’t work within the letter of the law they’re guilty of criminal misconduct in some form or another. How this isn’t the case here I’ll never know.

On a slightly higher note it is refreshing to see a head of a public agency take fully responsibility for the misconduct of their agency. Mueller, the head honcho of the FBI, plainly stated, “”I am to be held accountable.”

I’m looking at you Bush. I’m also eyeing you Cheney.

My First Week at Digg

The new sign at the Digg office

So I made it down to San Francisco in one piece. After spending a week in a hotel I’m now up in Concord, CA staying with Jeremy.

Tomorrow I start my second week at Digg. I can’t really talk about what’s going on or what I’m doing, but I’m surrounded by lots of geeky people and back in the thick of Silicon Valley, which is always interesting. As expected, things are exciting and there’s ton of potential everywhere.

One thing that will take some getting used to at Digg is that there are people who handle servers and such, which is new to me. At all my other jobs I was the PHP Developer/MySQL Administrator/Systems Administrator. At Digg I just say “Hey, Time, I need a DB.” or “Hey, Ron, can you upgrade GD?”

I don’t think I’ll be blogging about work very much as we have people who do that as well, but suffice it to say I’m excited about the job, city and possibilities.

Farewell Seattle

I’m a huge fan of Seattle and, with great dismay, I announce I’m leaving this fair city for San Francisco tomorrow morning. The LandRover is packed and the trip has been planned.

The route will take us through Oregon to Eureka, CA on our leg. We’ll be taking our sweet time down HWY 1 along the California coast all the way to San Francisco from there. It should be a great trip along one of the most fabled roads in the country.

I’m not especially happy to be leaving the Pacific Northwest, but what do you do when the big leagues call you up? I’ll miss the mountains, living downtown in a place I renovated myself, my friends and the city I’ve grown to love so dearly.

Thanks for everything Seattle!

Change can be good

I think anyone who knows me would say, without a doubt, I’ve changed drastically over the last two years since moving to Seattle. I haven’t changed as a person per se, but I have definitely changed my lifestyle. Here’s a small list of things that my old friends from Michigan simply can’t comprehend.

  1. I’ve participated in multiple 5k’s and triathlons.
  2. I own a TV, but don’t have cable. I rarely watch TV and consume 90% of my media online.
  3. I rarely drive. This last summer I was quite proud of the fact that I didn’t drive my vehicle for 3.5 weeks.
  4. I don’t eat fast food for the most part.

Now reverse that list and that’s how I lived in the Midwest. The two there that my friends from Michigan are simply astounded about are not driving and not watching TV. This got me thinking as to how much of an impact my move to Seattle has had on the planet. So I took a quiz that calculates my ecological footprint to compare my two lifestyles. I’m happy to report that I’ve saved an entire planet by moving to Seattle! Well, not really, but my ecological footprint went from a score of 23 (5.2 planets to sustain my existence) to 18 (4 planets to sustain my existence).

So, this isn’t really something to cheer about, but it’s definitely an improvement. To top things off I really like the new me. I like training for triathlons, I like being ignorant of pop media and I especially like not having to drive everywhere.

Change is good.

I'm employee #20 at Digg

It’s official. As of today I’m employee #20 at Digg. I sent in my resume in September fully expecting not to hear back, but over the course of the last few months it became apparent I was being considered for a position. I didn’t think much of it after not hearing from them for almost a month, but Brian Link sent me an email around the first of the year which turned out to be an official offer.

For those of you that don’t know, Digg is the 19th most visited site on the internet in the United States. It serves up more traffic than Wal-Mart, the New York Times or Best Buy. So, as you can imagine, I’m pretty excited about this opportunity. I’ll be arriving in San Francisco somewhere towards the beginning of February. If you’re in the area and would like to get pints please let me know.

Taking the job means that I won’t be doing any contract work and my open source projects will most likely sit idle for the time being. If you’re interested in maintaining Framework or any of my PEAR packages please let me know.