Weather: variable

More running last weekend, this time over Snowdonia's high point as part of a longer day on the Saturday. Greg and I started from Pen-y-Gwryd in glorious sunshine and ran over Moel Berfedd to Pen-y-Pass. From there it was over the Horns to Crib Goch (incidentally, the Horns are lovely!). We despatched Crib Goch with aplomb, passing most of the morning crowds on the approach and therefore getting the ridge itself mostly to ourselves. Warm in the sun, but cool in the breeze, the weather couldn't decide what it was doing all day. Continuing up Crib y Ddisgyl to Carnedd Ugain we could see the summit of Snowdon getting busy. A quick stop at the top and then down to Bwlch Cwm Llan, before climbing once more to Yr Aran. Nice to get some views (I was in cloud last time), before the long descent to the campsite.

Saturday's route in green (top-right to bottom-left) - I forgot my camera so there aren't any photos!

Saturday's route in green (top-right to bottom-left) - I forgot my camera so there aren't any photos!

Sunday saw us take up arms for round two of the battle with the Welsh countryside. It's fair to say that the countryside definitely took the upperhand to begin with. Parking at Aberglaslyn, we aimed for Yr Arddu on our way to Cnicht. Calling the terrain around Yr Arrdu a "godforsaken wasteland" is probably going a bit far, but it's definitely rubbish for running! We finally escaped the heather and made it up onto Cnicht. A great run down to Llyn yr Adar was followed by continuing undulation in a northwards direction for the rest of the day. The arrival of snow at Moel Merch, despite it being warm enough to run just in a vest, imbued us with a renewed sense of urgency, and it was with relief that I pulled up onto the last big summit of the day, Carnedd y Cribau. Another fast drop, this time to Pen-y-Pass, saw us once more waiting an inordinate amount of time for a Sherpa bus back to the car.

Snowdon Massif from Llyn yr Adar. The far skyline was our route the previous day. © Haydn Williams 2012

Snowdon Massif from Llyn yr Adar. The far skyline was our route the previous day. © Haydn Williams 2012

Brownie points were earned by giving a lift to an old lady who'd tried to walk a bit further than her aging legs could carry her; with a good deed for the day done, we headed home. I leave you with some quotes from Greg, arranged in order of how amusing I found them:

  1. (Running along Crib Goch): "Well if you fell from here, you'd really only graze your knees."
  2. (This might be my new mantra when trudging along knackered under inhospitable weather): "Still snowing, still going."
  3. (On approaching crags below Yr Arddu. Rudest comment of the weekend): "It's almost *too* nice to be Welsh."

Tags: , , , , , , ,

PHP Development in Eclipse

I used Eclipse on a Mac to work with Java during my PhD, so familiarity made it seem the logical choice for some recent PHP development I've been doing. This post runs through the various plugins I added to support the development process, including checking code quality, running unit tests, and creating documentation.

The first step is obviously to install Eclipse. To ensure compatibility with all the plugins mentioned, I found it necessary to download the standard version of Eclipse and then install the PDT tools afterwards. The dedicated all-in-one PDT version of Eclipse didn't play ball with everything I needed it to.

 

Version Control – Subclipse
I use Subversion (SVN) for version control, and Subclipse seems to to be the de-facto client for Eclipse. However, there are some pitfalls to be aware of. If you install Subclipse and then try to add a respository in the SVN Perspective, you may get an error telling you that you need version 1.7 or higher of the JavaHL library. This is part of the Subversion binary, so your copy of SVN must be out of date. If you nip over to Collabnet for the latest version you'll find that they only have 1.6, so instead you'll need to visit WANDisco. Once 1.7 is installed, you should then be able to connect with Subclipse using the JavaHL library. Thanks to peeps on Stackoverflow for pointing this out.

Unfortunately JavaHL still failed for me, telling me that the network connection closed unexpectedly. I tried to use the SVNKit adapter instead of JavaHL, but it turns out that SVNKit isn't supported in version 1.8 of Subclipse, (the most recent version). I therefore uninstalled Subclipse v1.8 and installed v1.6 instead. That still didn't work because apparently SVNKit doesn't currently support SVN 1.7 (see previous link). Anyway, this turned out to be all a bit misleading, because when I tried it everything just worked.

 

Debgugging – Xdebug
If you want to debug PHP, then you'll need either Xdebug or Zend Debugger. I chose the former for reasons I can't quite recall. But setting it up required the following steps in Eclipse:

  1. In Preferences > PHP > PHP Executables, set up your PHP executable. Mine, the default Lion version, was at /usr/bin/php, and php.ini was at /etc/php.ini
  2. In Preferences > PHP >  PHP Servers, set up your PHP server. I had to delete the "default" one first.
  3. In Preferences > PHP > Debug, set your debugger, server and executable.
  4. If you've changed the Xdebug port from the default of 9000 for any reason (I had problems with my initial Xdebug install, and that was one of the suggested fixes), don't forget to correct it in Preferences > PHP > Debug > Installed Debuggers.

 

Debugging with Xdebug. The 'debug' panel shows the methods which are currently running, while the relevant code is shown below. Panel on the right shows variables and their current values.

Debugging with Xdebug. The 'debug' panel shows the methods which are currently running, while the relevant code is shown below. Panel on the right shows variables and their current values.


Coding Standards – PHP Code Sniffer

To ensure that your code is up to standard(s), you can install PHP_CodeSniffer with PEAR:

pear install PHP_CodeSniffer

There's more detail on their homepage, including information on the –report flag to get a summary of the errors in your entire project instead of all the detail for every file. I'd recommend creating your own customised standard so you can exclude errors you're not bother about (variables with single-letter names, for example). Once you've done that, you can also make your standard the default to be used each time you run PHPCS.

PHP Code Sniffer summary report.

PHP Code Sniffer summary report.


Coding Problems – PHP Mess Detector

PHP Mess Detector does a good job of finding nasty bits of code. This includes 'dead' code that's never run, complicated loops / nested ifs,  It's worth reading the section on how to create a custom ruleset, because the defaults may include tests that you want to exclude.


Unit Testing – PHPUnit

Unit testing is a great habit to get into, and test-driven development takes this to its logical conclusion. PHPUnit and SimpleTest both provide unit testing in PHP; I chose PHPUnit because there seemed to be more material online about how to use it. To install PHPUnit you can use PEAR. Unfortunately PEAR wasn't installed on my Lion system, but you can install it using wget.  Unfortunately wget wasn't installed on my Lion system, but you can install it with a number of terminal commands.

Once wget is installed and then PEAR is installed and then PHPUnit is installed (!), you can set up Eclipse to run it as an external tool. However, it's much nicer to get it integrated into your Eclipse installation. To do this, I used MakeGood. The instructions on their website are pretty easy to follow and essentially boil down to:

  1. Install the MakeGood plugin from within Eclipse, using http://eclipse.piece-framework.com as the URL
  2. DON'T  ignore the lines about having to specify a PHP executable; I did (because I already had an executable defined), but for some reason the executable had disappeared from my Eclipse preferences and so I had to add it again after much head-scratching.
  3. DO display the MakeGood 'view' in your Eclipse window as soon as possible – it has a nice little message which explains what might be stopping you running your tests.
  4. A message about Stagehand_Testrunner led me to install that separately, using PEAR (instructions are on the Stagehand website)
  5. Despite adding my PEAR folder as a library to the project build path, I was still getting a message saying that PHPUnit_Framework_TestCase could not be found when I ran a test. I resolved this by adding /Users/Haydn/pear/share/pear/PHPUnit to the build path too, and using require_once in the test class:  require_once 'PHPUnit/Autoload.php';
MakeGood showing a successful test in Eclipse.

MakeGood showing a successful test in Eclipse.

Once PHPUnit is working correctly, if you want to test database operations too then you'll need the DbUnit extension. There's extensive help regarding this whole subject area in the PHP Unit manual. Note that SQL Server isn't supported by default.

 

Documentation – PHPDoc
If you're documenting your code then you'll want phpdoc – installation instructions are on their website. Just use the two PEAR commands on their homepage, and ignore other websites (which generally omit the '-alpha' reference). If you try and generate some documentation but get an error about GraphViz not being installed ("Unable to find the `dot` command of the GraphViz package. Is GraphViz correctly installed and present in your path?"), go to the GraphViz website to download a .pkg file for Lion and install it. If you get a message about timezones, ensure that the correct one is set in your php.ini file (e.g. date.timezone = Europe/London).

 

Automation – ANT
Once all the above are in place, it's nice to be able to run them all together. You can use ANT to do this; here's an example of my ANT build.xml file:
<?xml version="1.0"?>
<!DOCTYPE project>
<project name="MyProject" default="test">
    <property name="docs_dir" value="docs" />
    <property name="log_file" value="MyLogFile.log" />
    <target name="dtd" description="Creates a DTD for this build.xml file.">
        <antstructure output="project.dtd"/>
    </target>
    <target name="clean" description="Deletes temporary and compiled files.">
        <delete dir="${docs_dir}"/>
        <delete dir="output"/>
    </target>
    <target name="messdetect" description="Runs PHP Mess Detector on PHP files.">
        <exec executable="/Users/Haydn/pear/bin/phpmd" failonerror="true">
            <arg value="." />
            <arg value="text" />
            <arg value="anciliary/PHPMD_custom_ruleset.xml" />
        </exec>
    </target>
    <target name="codesniff" description="Runs PHP Code Sniffer on PHP files.">
        <exec executable="/Users/Haydn/pear/bin/phpcs" failonerror="true">
            <arg value="." />
            <arg value="--standard=MyStandard" />
            <arg value="--extensions=php" />
            <arg value="--report=summary" />
        </exec>
    </target>
    <target name="test" description="Runs all PHPUnit tests.">
        <exec executable="/Users/Haydn/pear/bin/phpunit" failonerror="true">
            <arg value="test" />
        </exec>
    </target>
    <target name="document"  depends="clean" description="Generates documentation for PHP files.">
        <exec executable="/Users/Haydn/pear/bin/phpdoc" failonerror="true">
            <arg value="-d" />
            <arg value="." />
            <arg value="-t" />
            <arg value="${docs_dir}" />
        </exec>
    </target>
    <target name="build" depends="clean,messdetect,codesniff,test,document" description="Run everything.">
    </target>
</project>
Next?
The next step is to move to continuous integration, using packages like Cruise Control or phpUnderControl, which will automatically test and build your code on a regular schedule. As a one-man project I always know the status of my work, so that's not been necessary so far. Hopefully the above will be of help in getting you up-and-running with a decent PHP development workflow in Eclipse.

Tags: , , , , , , , , , , , , , ,

Running Wild

It seems like an age ago, but was only last weekend. Before all the snow which is currently causing much consternation across the upper half of the UK, there was some decent weather. Greg, Arno, Rob and I salvaged an aborted trip to Glen Shiel by visiting north Wales instead for some running and climbing. After a leisurely start on Saturday we began our run with a bang, slogging up the steep ascent to the top of Y Garn on the Nantlle ridge.

Arno and Rob hit the first summit of the day - Y Garn on the Nantlle ridge. © Haydn Williams 2012

Arno and Rob hit the first summit of the day - Y Garn on the Nantlle ridge. © Haydn Williams 2012

From there, we traced a route southwards over a couple of other tops on the ridge, then down to the Princess Quarry and over Moel Lefn, Moel yr Ogof and Moel Hebog. After crossing Cwm Cyd and reaching the top of Moel Banog, Rob and Arno took the direct route back to Beddgelert whilst Greg and I pushed on over Cwm Bychan before dropping into the village and recovering with an ice cream.

The best bit of the day? The amazing descent from the ridge. © Haydn Williams 2012

The best bit of the day? The amazing descent from the ridge. © Haydn Williams 2012

We covered 20km and between 1500m and 1800m of ascent (depending on whether you believe my GPS or my OS-mapping software!). The height estimate seems a little high, given that I still felt pretty good at the end of the day (especially strange after my complete meltdown on the Edale Skyline the week before).

That evening I hopped on a Sherpa bus to go and pick the car up, and then took it for a spin. Dad had kindly continued my recent run of "borrowing nice cars for trips to Snowdonia", and given me a Focus ST to play around with. Suffice to say it was pretty swift and actually turned out to be more fun than the Boxster.

Focus ST. Pretty *and* fun. © Haydn Williams 2012

Focus ST. Pretty *and* fun. © Haydn Williams 2012

Sunday started beautifully, with not a cloud in the sky as I dropped the others at Idwal for their walk up to Cneifion Arete. I parked further along the Ogwen valley and moved quickly up the north ridge of Tryfan (which is the obligatory Snowdonia route in blazing sunshine). My "easy day" got a little harder as I despatched Tryfan in just over an hour, and decided to continue onto Glyder Fach. I could see Greg and Arno on Cneifion Arete from the top of the upper cwm headwall, so carried on over Glyder Fawr to Llyn y Cwn.

I panicked a bit when confronted with this sight on arrival at Cwm Cneifion. Needless to say, Greg was behaving impeccably and the helicopter looked to be doing training rather than rescuing. © Haydn Williams 2012

I panicked a bit when confronted with this sight on arrival at Cwm Cneifion. Needless to say, Greg was behaving impeccably and the helicopter looked to be doing training rather than rescuing. © Haydn Williams 2012

Still with time to spare I pushed on over Y Garn, and got back to the car about five minutes before Rob, who'd walked up Senior's Ridge and returned over Y Garn too. I just had time for a quick power nap before Greg and Arno returned from the escapades on Cneifion Arete, and we all trundled home tired but content.

My point-and-shoot camera's mediocre attempt at doing justice to the panoramic view from the Glyders. © Haydn Williams 2012

My point-and-shoot camera's mediocre attempt at doing justice to the panoramic view from the Glyders. © Haydn Williams 2012

 

 

Tags: , , , , , , , ,