Add tests

Adds a very simple PHPUnit test.
Refactored use of some procedural code.