Fix errors in tests

The relevant bits here are in commit d98a4e89edb3d21f5786f7eec1d0f92d1ba0f95a and fa56a380aa7cd94df91a956baf54cd5d228b2aa2.

Some tests were throwing errors if you ran them on a system with system-wide error_reporting turned on. I've fixed these errors (but one), as the errors could influence the test results.