Improved URL handling

Work around PHP's brokenness a bit, set correct default port for SSL
Add PHPUnit bootstrap/config and a few tests