Making sure to check if we have an active output
buffer before trying to grab its contents, especially
for PHP-fpm, since `fastcgi_finish_request()` closes
all output buffers automatically

This fixes #163
Fix tests that fail on HHVM due to inconsistencies with Zend on key()

https://github.com/facebook/hhvm/blob/master/hphp/doc/inconsistencies#L23

HHVM does not reset the internal array cursor when an array is copied. Zend 5.5
does, so when an array is passed to a function (like `$sample_data` in the fixed
tests) the internal cursor is reset. For 5.6 the maintainers have specified that
how the internal cursor is copied is an implementation detail and may change without
warning. So it's best to be explicit and not rely on key() or current() at all.

I just fixed the tests for which this causes problems on HHVM as part of the effort
to get klein.php to 100% for HHVM.