Archive for September 2008

Unit testing in PHP with PHPUnit

With this dynamic data model that I am currently building in PHP, I found that for quite a complicated solution I had no unit testing at all.

After searching around I found PHPUnit, however, it all hinted at a Linux only environment. A short while later I found a blog that described how to set it up for Windows: http://usingzendframework.blogspot.com/2007/12/setting-up-phpunit.html. I use Xampp, so I did not have to change the memory limit.

Once installed I used the online pocket guide to start me off: http://www.phpunit.de/pocket_guide/index.en.php

Inside my code folder I created a tests folder where I placed all my php tests, inside that I created an includes folder for all the test related code.

folders.jpg

The first thing that the common include does is turn on all the error reporting an strict reporting. This should ensure the most quality coding.

<?php
error_reporting(E_ALL | E_STRICT);
require_once('PHPUnit/Framework.php');
?>

Once that is done, I could start with writing all the tests.

<?php
include('includes/common.php');
class ExampleTests extends PHPUnit_Framework_TestCase
{
 public function testSomeObjectTest()
 {
  /* Test code here */
 }
}
?>

Once that was done, I created a msbuild script to test them all using the TestSuite class

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
    <PropertyGroup>
        <BuildDir>$(MSBuildProjectDirectory)</BuildDir>
    </PropertyGroup>

    <ItemGroup>
        <CodeFiles Include="$(BuildDir)***.php" Exclude="$(BuildDir)**.svn***.*;
                                                           $(BuildDir)**tests***.*" />
    </ItemGroup>

    <Target Name="Build">
        <CallTarget Targets="RunTests" />
    </Target>

    <Target Name="RunTests">
        <Exec Command='phpunit --verbose "$(BuildDir)testsTestSuite.php"' WorkingDirectory="$(BuildDir)tests" />
    </Target>

</Project>

I had to add the framework folder and the php folder onto the PATH environment variable so that I could just call msbuild from the commandline

RGB to Hex Converter

I have been working on my dads website, using a wordpress theme generator and this handy colour scheme book that I bought a couple of years back. (Yeah! I have a book with lots of colour swatches in it. I’m borderline dyslexic and don’t have any colour co-ordination.)

This book, has a small section in the back for web safe colours with hex values, the rest is all RGB and CMYK values for the printed page. Because there is a greater range of swatches in the first half, I created this small app to quickly turn an RGB value into Hex:

RGB Converter Image

Features: 

  • Automatically copies the hex value to the clipboard
  • Automatically skips to the next RGB colour value after a valid 3 character colour has been entered (enter 0’s for padding)
  • Ocassionally will skip over an RGB colour field
  • Pressing any other key when an RGB colour field has focus will automatically validate that field

Grab the source code here

It is not a perfect solution but it allowed me to quickly key in an RGB value and get the hex code. The result was quite good actually, quite a few of the RGB/CYMK printed colour schemes worked well in a web browser.

HWMonitor, temperature monitor alternative

With the install of Vista, I have had some issues with my system monitoring software. The new ASUS PC Probe II leaves windows all over the place and is difficult to read and quickly check the temps.

 The nVidia hardware monitor worked for a short time up until I installed some other nVidia drivers which broke it. I shortly also learned that it wasn’t supposed to work in Vista either =/

 So I was out of options, I had nothing to monitor my system with. I am a little nuerotic about it, I am constantly worried that my old hardware will melt the next time I play a game or a fan will fail and the computer won’t tell me in time. I have been nursing my computer for the past year, to keep it ticking over until I get a new machine.

CPUID’s Hardware Monitor – http://www.cpuid.com/hwmonitor.php solved all these issues. It hooks into all the sensors on your machine and reports thier values. I now have a one application that soaks up very little CPU time to monitor everything on my system. Even some sensors that I didn’t know I had!

It can get a few things wrong, there are a couple of my sensors that don’t move or report wrong values. They have a pro version for 20 euros and even a development SDK for 999 euros… SDK is a bit much for just me, might get pro after a while.

Wordpress Theme Generator

I am currently creating a website for my father. I chose Wordpress as a base, its nice simple UI will be adequate for what he needs to do, it has a simple plugin system and I should be able to rapdily design a website for him.

Well its been 4 weeks and I am still stuck trying to design a template. The saviour of the day however is A Wordpress Theme Generator by Yvo Schaap - http://www.yvoschaap.com/wpthemegen. Using this really simple generator, I have been plugging in various colours before I get something that looks right. I will now go off, modify the template myself and provide some drops for dad to look at :)

FileZilla, the SmartFTP alternative

With SmartFTP not offering a free license anymore there is now a space for another robust FTP client. I don’t blame them, they offered such a high quality product for free for such a long time I could see that they would do this at some point. However I feel that they could have offered a really simple cut down FTP client for the simple joe, I only need to download or upload the odd file. Maybe change a few permissions, I don’t use all the features that SmartFTP offered.

As a result, I went hunting for an alternative FTP client and FileZilla ranked highly: http://filezilla-project.org/ Its an open source client and server (separate installs) and does the job nicely.