public function testEnd() { $prevShutdown = ResponseUtil::$shutdown; // Test with string ResponseUtil::$shutdown = 'echo "responded";'; ob_start(); try { ResponseUtil::respond('I have ', true, true); $echoed = ob_get_clean(); } catch (Exception $e) { ob_end_flush(); $this->assertTrue(false, 'Ran into error in ResponseUtil::respond! ' . $e->getMessage()); } $this->assertEquals("I have\nresponded", $echoed, 'Shutdown code (string) did not run properly!'); // Test with a closure: ResponseUtil::$shutdown = function () { echo "responded"; }; ob_start(); try { ResponseUtil::respond('I have', true, true); $echoed = ob_get_clean(); } catch (Exception $e) { ob_end_flush(); $this->assertTrue(false, 'Ran into error in ResponseUtil::respond! ' . $e->getMessage()); } $this->assertEquals("I have\nresponded", $echoed, 'Shutdown code (anonymous function) did not run properly!'); ResponseUtil::$shutdown = $prevShutdown; }