Implement phpunit test class.

As a result, a few undeclared variables are fixed. Query test currently fails.
Run the test with: sh test/testrunner.sh