Testing Through PHPSpec

This adds testing to some of the code. There's not a huge amount of code coverage yet, but I want to get these tests into master since it also contains rewrites to make code easier to test. These rewrites will inhibit development off master until it this branch is merged in.