preCalls++; if ($this->failPre) { return new HTTPResponse('Fail pre', 400); } $response = $delegate($request); $this->postCalls++; if ($this->failPost) { return new HTTPResponse('Fail post', 500); } return $response; } public function reset() { $this->preCalls = 0; $this->postCalls = 0; } }