phing / unit tests and global variables

Yesterday I thought I’d move one project over to using phing (with the end goal of hopefully getting some sort of Continuous Integration setup in place, with graphs and stuff to show the customer).

All went reasonably well – svn update, php documentation generation, php code sniffer tasks etc were all in place. Unfortunately when I got to do the unit tests (simpletest) things failed, and it seemed to be the case that no global variables in use within the code base were available. As my brain finally realised why this is the case this morning, I thought I’d better write a blog post in the hope it may help someone else in the future.

The code base itself is ‘legacy’ – in that it’s been pulled in different directions over the years before we got our hands on it. There’s bits of procedural code (e.g. query(..) which seems to just be the same as calling mysql_query(..)) and object oriented ($db->query(..)). Mixed in with this is a liberal use of global variables (e.g. $db, $database_name, $software_root and so on).

My unit tests, when run via a script on the command line look like :

<?php
require_once('common.php');
require_once('simpletest/reporter.php');
require_once('simpletest/unit_tester.php');
$test = new GroupTest('my tests');
$test->addTestFile('WhateverTest.php');
$test->addTestFile('FooTest.php');
exit($test->run(new TextReporter()) ? 0 : 1);

And worked fine.

Within the code base, there is one include file within the application which defines a number of variables, on the assumption it’s at the top level scope – e.g.

$database_name = "blahblah_live";
$db = new Database($database_name, $database_username, $database_password, $database_host);


Which works fine. However, because $db hasn’t been explicitly defined as a global variable, when the tests are run through phing – they run within the scope of a function, and hence the global variables aren’t available (because they’ve not been implicitly registered as globals – the code just makes an assumption that they are).

So, to fix it, I just need to find all the variables defined in the script, and make them explicitly global.

i.e.

global $db;
global $database_name
$database_name = "whatever";
$db = new Database(.....);

One step closer; perhaps soon I’ll be posting about getting Xinc or something similar working.

My First Marathon

But will it be my last?

To detail it here – hopefully instead of telling everyone the same thing – and to remind myself next year… here’s how it went.

We arrived in Stratford for the Shakespeare marathon at about 8:45am, changed, herded toddlers and children towards the start and did the toilet ritual. The start line had moved from last year, but it was obvious where to go. Then we spent about 15 minutes standing around waiting for the start klaxon.

Obviously the start was crowded; there were fat/slow/lazy people everywhere – as I did a lap around the town centre, I just found myself zig-zagging through them all and getting frustrated somewhat. It was nice to have Rowan, Kat, Jenny, Emily, Rachel, Helen, Vickie, Anderson and Bailey all looking on as I raced past. Suffice to say, I was full of beans at this point in the race 🙂

I knew I was running relatively quickly, at least for the first half marathon – I did 12 miles in about 1 hour 30, or thereabouts – and enjoyed myself certainly until sometime after this point, which makes me wonder if I should do half marathon’s in the future and not bother with full ones (now I’ve done it… ) but that’s an argument for another day.

Anyway, at about 16(?) miles, I went to the loo; while sitting down on the toilet (hey, at least I didn’t just hide behind a hedge) my legs were busy shaking. By about 18 miles I was making a conscious effort to slow down a little, and keep my heart beat at around 150-156. I suspect I generally failed at this. In my mind I knew I had little more than my daily morning run left to complete – but it certainly dragged on. My fingers and toes had been getting slightly numb since perhaps 18 miles. Maybe earlier.

The last 5-8 (?) miles of the marathon involve running down a straight disused railway track – the Greenway – this dragged on for a long time. Especially as we’d covered part of it on lap one. By about 20 miles, my stomach area was starting to cramp slightly; By 22-23 ish miles, I had slowed down quite a lot – but discovered myself overtaking walkers doing the half marathon. My vision started to blur slightly, and my legs felt pretty useless perhaps at about 24 miles – and time / distance seemed to drag on and on.

Eventually I returned to the recreation ground/park in the middle of Stratford for the finish. In retrospect I could have upped my pace at bit at this point – but it still seemed like there was some distance left to run, and I couldn’t remember the route that well from last year – so it wasn’t until the last corner that I sprinted what is probably the last 50 metres to the finish line. My legs were numb, I was just glad the ground was quite flat as I couldn’t really feel them. Thankfully I didn’t trip which would have been a pain.

Once over the finish line I just wanted to collapse and remove my t-shirt. My shoulders had ached for about the last hour. I staggered back to where the waiting family were and promptly collapsed on the floor. My legs then took turns in cramping in alternate muscles – Jenny didn’t approve of my method of punching myself in the appropriate cramping muscle and helped me stretch – which I think helped.

So, anyway, would I do it again? Yes. But I somehow need to get a better sense of pace. On my own, two to three weeks ago – with no one to chase – I did 24 miles in about 3 hours 30 mins and that was difficult enough; yet I did the entire marathon in 3 hours 35 mins on Sunday. I can see that I probably went too quick for the first half, but I’m not sure I have the discipline (?) to slow myself down in the first half enough to have an effect towards the end.

So, Nottingham’s marathon beckons sometime in September, I think.

If I’d done just the half marathon, I’d have been in good form at the end (not tired, able to run the last mile or so very quickly etc); yet I did the full marathon and found it pretty hard going. So, should I focus instead on just doing half marathons quickly? I don’t think I have the lanky runners physique which suits marathon runners…..

Update: apparently I was 184th out of nearly 900 runners. 🙂

Twitter Weekly Updates for 2010-04-25

  • Stratford marathon done – 3hrs 35m. Did first 12 miles in 1hr 30. Failed to pace myself. Legs enjoyed cramping for 30 mins after. Good fun #
  • Podrunner's PowerTools mix – 174bpm; I wonder if this will help me run or not…. http://bit.ly/vXbcS #
  • Hmmm. Not long now. Best pull finger out and move it. Alarms don't wake toddlers. An interesting fact perhaps. #
  • Spoilt dog http://twitpic.com/1i3avu #
  • Palringo seems pretty good (Im client for iPhone, pc, mac etc) #
  • Marathon tomorrow. Better start peparing. Food. Food. Music 4 iPod and check schedule. #
  • "this shirt would look good on your bedroom floor" – you're fat and ugly, so it's not going to happen for you mate, let's be honest. #
  • Ah, tetris – http://www.last.fm/music/MidTown+Dickens/_/Tetris #
  • I like playing tetris in the shower…. tetris is my favourite video game… (lyrics to a song being played in the office) #
  • Since poundland opened in bromsgrove all other shops seem to have started to price things at £1. Wasn't it 99p before? 😉 #
  • Reasons to be a dog: #1 good looking women pet you randomly and scratch your back. #2 you can't go in most shops. #
  • Shorts. Thick jumper. Hmm. Dogs have it easy – none of this clothing nonsense. #
  • Taking a day off work just so Eon can change the electric meter is not going to happen. FFS be more specific than 8-8pm. 1 hr slot perhaps? #
  • Dog's hungry. #nickcleggsfault #
  • I need to shave/shop/eat. #nickcleggsfault #
  • RT @PalePurpleLtd Interviewing students for placement year – my findings – http://bit.ly/cSUD4v #
  • RT @guardiantech Facebook introduces Docs, based on Microsoft Web Office http://bit.ly/cnHviA #
  • Lunch time view. Bit better than normal. http://twitpic.com/1ha3r5 #
  • RT @carolinegoodwin Spoof Daily Mail article http://twitpic.com/1h8ik8 Quite funny #
  • More spam from prospective mps #bromsgrove #straight2recycling just have a f'ing web presence…. #bromsgrove #
  • Bad things today: 1) diesel £1:20 a litre; car drank 45+ litres. 2) tired 3) poss. last run before Sunday – better make it count (7miles) #
  • Pershore looks quote nice. Wish bromsgrove wad as good #jealousofcustomersoffice #
  • Now, can I find a running hat in preparation for Sunday ? #
  • Stourbridge road properly blocked; looks like they've nearly finished (hole filling up) http://twitpic.com/1gru97 no more cheating drivers! #
  • Don't appreciate being overtaken by an old woman on an electric bike while running uphill. She got away on the downhill. Old fat lazy Cow. #

Post #1 on the UK Election…. (Bromsgrove)

So the Lib Dems might finally shake things up – I’ve not supported them before, and still dislike many of their policies – but I do feel that were they to get in, there would be an adequate shake up of the establishment in Westminster (PR or something similar would be a good move for a start – I’m increasingly fed up with (I feel) politicians getting ‘safe’ seats and effectively not listening to their constituents).

Unfortunately I suspect the polls will keep remain somewhat level, or Mr Clegg’s honeymoon will end as voters are either disillusioned by the ongoing press attention and we’ll just end up with Labour winning as our First Past the Post system seems to be favouring them for some reason.

At the moment I’m not sure who I’ll vote for; our local replacement Tory couldn’t be arsed to reply to an email I sent which just asked where he stood on DeBill / WhatDeBill etc – which didn’t particularly impress me. I’d expected to effectively get a copy+pasted generic reply saying whatever the party line was, but he couldn’t be bothered with that. Oh, and he also seems incapable of using Twitter/Facebook etc.

Having said that, my local LibDem candidate has figured such things out (website / facebook etc) but judging from what’s fallen through my letter box (and then straight into the recycling box) he is being outspent by the conservative campaign, in a seat where my vote counts for 0.09 of a ‘normal vote’ (clearly some votes are more equal than others?!) I can’t think he can be very optimistic.

Twitter Weekly Updates for 2010-04-18

  • Sanders park is busy. Lovely day #
  • Hmm. Lidl almond ice cream things. #
  • Hockey match done. Lovely day. #
  • The coffee which has been keeping me alert/awake at work turns out to be decaf. A definite #wtf moment. #
  • I love chilli. #
  • RT @carolinegoodwin they're a rough lot in Bromsgrove http://bit.ly/dg8Tzt (woman banned from alcohol buying) #
  • So… The sky. Grey from ash? Is that what I can smell? Or is it just normal boring overcast Britian with local pollution? #ashtag #
  • More & more drivers think "road closed" doesn't apply to them (Stourbridge road, bromsgrove). Why is it closed, why not traffic lights? #
  • RT @poorlydressed Someone Get the Lifeguard – Poorly Dressed People of the World – Fashion Fails http://bit.ly/awSYm9 #
  • RT @dvntownsend Today's FREE MP3 from @AOLRadio is "Hyperdrive" from @dvntownsend: http://ow.ly/1yve6 + free sampler from @AmazonMP3: … #
  • Kick Ass is an excellent film – one of the best i've seen recently; def. better than avatar / green zone etc http://is.gd/bs2j0 #
  • Stourbridge road is much nicer closed. Perhaps I need to buy some road closed signs and dig a big hole in it …. #bromsgrove #
  • Not impressed that this stupid griffin iPhone case is broken. Can haz metal case plz? #
  • The dog is changing career – cat chasing is so passé, fly catching is the way forward… #
  • Wow. Bank paid me 14p in interest this last year on our current account. Why bother? #
  • Potential office viewing booked for later today; <30 metres from telephone exchange; I'm not a bandwidth whore… honest. #
  • Doesn't like being woken up, by his calf muscle cramping. #
  • My MP Julie Kirkbride didn't bother voting on #debill Find yours http://www.VoteThemOut.co.uk #

Twitter Weekly Updates for 2010-04-11

  • You'd think rubbing 24 miles would mean the dog wouldn't need walking again. Apparently not. #
  • God. Can't put it off any longer. Must shower and cut the lawn, else it'll become hay. Hoping body works again. #
  • Body now rebelling against 3hr 20 min run (bromsgrove -> Birmingham and back). Hope it was about 24-26 miles. #
  • RT @glynmoody A letter to my MP – http://bit.ly/aeLsTh – brilliant letter about the Digital Economy Bill/Act; wish I'd written it #deact #
  • Spotting the 10k runners go past sanders park. Lovely day. #bromsgrove #
  • We're all going on a toddler hunt. What a beautiful day. We're not Ill. Uh oh. He is! Grump grump grump. #
  • Stupid classic iPod. Just turn off ffs. *sigh* fine! I'll give you to a 7 year old who'll care and make full use of your abilities. So long! #
  • Busy making single threaded perl backup scripts parallelised. #
  • RT @loudmouthman hey O2 you just kept my business http://ow.ly/1wsHr #DeBill (not as good as talktalk tho..) #
  • Digital Economy Bill it's a wash up – http://www.talktalkbog.co.uk/2010/04/08/digital-economy-bill-its-a-wash-up/ #debill #talktalk #
  • Where I live I have the power of 0.1 votes. See your result at http://voterpower.org.uk #GE2010 #VPI #
  • The dog has it in for me. Twice he tried to trip me up while running. Grr. #
  • Morning motivation – coffee – http://www.myconfinedspace.com/2010/04/08/coffee-posters/ #
  • Interesting southpark episode (s14e04) taking the piss out of facebook & tron …. #
  • Upgraded Mac Mini's RAM to 4gb; shame none of the 'tutorials' online were up to date. Anyone want 1gb of DDR3 8500S RAM? #
  • Oi! Don't piss there [door mat] you stupid dog! GRRR. (We'd only come back from a run 1-2 hours ago). He accidentally fell nose first on it. #
  • Looks like a fine evening for a run. I wonder how many runners I can overtake….. #
  • We won't be attending coilwindingexpo.com in Germany. They sure put plenty of effort into targeting that letter-shot #marketing #spam #fail #
  • RT @loudmouthman I swear I was watching Scrapheap Challenge as MPs tried to make some sort of Copyright law from outdated ideas. #DeBill #
  • .@Pewari I think mps pair off againt opposing parties so they don't need to turn up to everything, Plus someone has to feed the ducks#debill in reply to Pewari #
  • It's all very well that you stock the best razor (kos azor) asda, but do you think you could sell blades for it too? #
  • You know you're onto a "winner" when you see a html drop down containing values like "title ASC" "price DESC" etc #security #sqlinjection #
  • RT @glynmoody Unknown root certificate in Firefox – http://bit.ly/9yeuw8 ouch #firefox #security #
  • Finally found the eclipse 'accept remote session' xdebug setting. Now it's usable (xdebug, eclipse remains slow and nasty). #xdebug #php #
  • id3tag – I am not impressed with your lame error message of "Abort trap". #
  • It seems Dr @carolinegoodwin fixed the dog's limp yesterday; back to having four working legs etc etc 🙂 Woof! Woof! #
  • Toddler tractor power http://twitpic.com/1dddwf #
  • Looking forward to tractor assembly. 🙂 #
  • Beer; Chocolate; Relaxation #
  • I like the Tory election posters up ATM. They seemed everywhere in Kidderminster – is it a marginal seat or something? #

Twitter Weekly Updates for 2010-04-04

  • Latest farm health and safety device 'promise' (this is real… Hang it on broken stuff so others know) http://twitpic.com/1d5w0u #
  • Reason 501 that religion is bad – http://nsfw.myconfinedspace.com/2010/04/03/whip-it-whip-it-good (page decorations are nsfw, image is ok) #
  • Good run – shame tripod couldn't keep up and had to be left behind. Dog seems to be going through a bad patch lately. #
  • F.it. No blank CDs at home to burn ubuntu onto to do an install. Off to the office I go. #
  • In my usual manner I'm fixated on one musical artist atm – Devin Townsend thanks @moobert & @aypok Plenty of bad air guitar/drums. #
  • American deluxe sized burger – http://www.youtube.com/watch?v=XqIWPvCgi9g …. bigger than most men. #
  • I've got swingers elbow :-/ #
  • Bromgrove council have failed wrt the car park layout outside asda. Nice waste of money. Motorists can't get back to the empty part. #
  • More hail / rain. Now if the dog would only let me pull the thorn out of his foot, and not throw up pork chop… we'd be onto a winner. #
  • Everyone seems to be buying lots of crap. Wish they'd get out of my way. #
  • RT @Surfrdan LOL Nice one RT @VecchioJo: wish i was this good an artist http://i.imgur.com/JEcO1.jpg ++ 🙂 #
  • Perhaps I need to quit my peanut butter on toast addiction first though… 4 weeks to first marathon (Stratford) #
  • Possible blisters between my legs; sore nipples and a filthy dog. Why do I bother? Oh, yeah, so I don't turn into http://bit.ly/cCWXi2 #
  • Body appropriate tired after longish run; time to clean up, shop, mess with computers and eat. #
  • Support world domination. Buy a book and t-shirt …. http://www.scottsigler.com/thestarter #thestarter #podcast #fakefootball #scifi #
  • Potential office above chippy. Looks promising. We might get very fat though. Nice chips tho. #
  • Twitter seems almost devoid of April fools. I'm not complaining. Toddler pulling one on me now – by having a lie in …. #
  • Will anyone come up with a believable/original april fools prank? #
  • 'NO!… Scissors do not go in the mouth Rowan!' #
  • The dog's had a hair cut and now is attacking a gigantic chew http://twitpic.com/1c55e8 #
  • Look prospect customer, if you have a rush job that needs completing in 32 hours, wasting 6 hours by not sending spec till 5pm does not help #
  • I just donated to stop the Digital Economy Bill http://bit.ly/dc7B1u #38degrees #debill #
  • RT @birminghampost Council blunders caused Brum municipal golf crisis, http://tinyurl.com/yabxvxz <- WTF? Slow news day? #
  • Hmm fail me. Today is clearly a cottage pie DAY #
  • Rowans asking for seconds. Clearly today is a cottage pie week. #
  • Stupid American(s): I AM gingerdog@gmail.com – NOT YOU. Stop requesting password recovery. It's not going to work. KThxBai #
  • Patch been to vet; lactulose is soln. #1 .. suspect a bone is stuck in his gut causing irritation. If no improvement by Weds, x-ray etc. #
  • Hmmm. Awake. Listening to what sounds like a dog being sick. He seems to be sick a lot lately… 🙁 #
  • RT @guardiantech Ofcom plans to cut cost of calls to mobiles http://bit.ly/b7EAs8 #
  • Wholemeal toast + peanut butter FTW. #
  • The dog instantly recognised the sound of a dog food can opening and appeared. Strange when I've hardly ever fed him canned meat before #

Twitter Weekly Updates for 2010-03-28

  • work meeting over; time to go shopping or something. #
  • Dear #Lazyweb I'm looking for 400-600sq feet of office space in/near Bromsgrove town centre (enough for 4 desks etc). #
  • Google Chrome Still The Unhackable Browser http://thenextweb.com/google/2010/03/28/google-chrome-remains-unscathed/ are ff's days numbered? #
  • the free @digg app is here for iphone! they're giving out 1 tricked ipad each day for 2 weeks to celebrate! http://bit.ly/diggapp #
  • Bromsgrove hockey 4ths. Won 2-0. Yey. My first real game in 13 years… #
  • It'll never cook if I keep stirring and watching… Apparently. #
  • RT @guardiantech News Int. starts paywall for Times and Sunday Times (UK) from June. £1/day, £2/week. Will you pay? — hahaha. No. #
  • Had 2 industrial year applicants so far; both with SQL injection flaws on their portfolio sites. #php #security #fun #
  • Why do I always want more peanut butter on toast? #
  • Just entered the Nottingham Marathon – http://www.experianfestivalofrunning.co.uk/ – September 12th 2010… #
  • I've just asked Harriet Harman to give the #debill a real debate. Please join in and RT http://bit.ly/bJ3HwF #38degrees #debill #
  • Soon it may be time to wake up. Soon. #
  • Firefox 3.5 was almost unusable on this acer aspire one; switched to google-chrome – netbook becomes usable and responsive. #
  • Patch enjoying the fruits of my labour http://twitpic.com/1aaiy8 #
  • The dog is eating better than the toddler. Shepherds pie – rejected. The dog and I enjoyed it at least. #
  • Anatomy education by colouring in parts of the dinosaur. Toddler style. #
  • Hmm. Had better not tell anyone I turned the oven on but wasted 10 mins as it wasn't turned on right 'oven' just 'light+fan+pretend' #fail #
  • Neighbour has what looks like a mountain bike with an engine. I tried not to stare #

Running routes

I’ve used http://www.favoriterun.com for years now (See e.g. http://favoriterun.com/account/public_user_profile/5369 ). However, today Chris pointed me at http://gb.mapometer.com/en – which does a far better job of plotting routes (e.g. auto-follow road; calorie guess-timation etc).

Unfortunately it doesn’t seem to allow the public to see who plotted a route – or see any other information about a route – apart from it being plotted on a map.

So, here’s a few of mine :

Bromsgrove to Kidderminster (21.94 miles)
Bromsgrove – Timberhonger – Droitwich – Canal – Finstall (19.48 miles)
Bromsgrove – Stourbridge Road – Swan Lane – Catshill (5.94 miles)

If only they had twitter / facebook or some means of ‘showing off your running routes’ …. silly people.

zencart security crapness

Today, I logged into one server to have a rummage and see if I could free up some disk space… on a whim I do an ‘ls’ of /tmp and find a file called ‘att1.txt’. Hmm. Lets take a look – ‘head att1.txt’ gave :

#!/usr/bin/perl
#  ShellBOT
#  0ldW0lf – oldwolf@atrix-team.org
#      – www.atrix-team.org
Ah, pants. Timestamp on the file matches a request to a Zen-cart instance :

... POST http://....../admin/record_company.php/password_forgotten.php?action=insert
... POST http://..../index.php?main_page=products_all/admin/record_company.php/password_forgotten.php?action=insert
... GET /index.php?main_page=products_all/images/6e072.php?site=http://...../index.php?main_page=products_all/images     /6e072.php

It turns out there was a security update for Zen-cart sometime ago – see http://www.zen-cart.com/forum/showthread.php?t=130161

Suffice to say the various attackers had left a few files on the filesystem; thanks to ‘find -user www-data’ these were easy to find and remove. Interestingly Zen-Cart suggests you rename the ‘admin’ directory – I wonder how many people don’t (in this case) or do it to e.g. ‘admin.old’ …

*sigh*