/** * @covers think\Response::error * @todo Implement testError(). */ public function testError() { // round 1 $msg = 1001; $data = "data"; Config::set('default_return_type', "json"); $result = Response::error($msg, $data); $this->assertEquals($msg, $result["code"]); $this->assertEquals($data, $result["data"]); $this->assertEquals('javascript:history.back(-1);', $result["url"]); $this->assertEquals("json", Response::type()); $this->assertEquals(3, $result["wait"]); // round 2 $msg = "the msg"; $url = "www.thinkphptesterror.com"; $result = Response::error($msg, $data, $url); $this->assertEquals($msg, $result["msg"]); $this->assertEquals($url, $result["url"]); // round 3 异常在travis-ci中未能重现 // $this->setExpectedException('\think\Exception'); // FIXME 静态方法mock // $oMockView = $this->getMockBuilder('\think\View')->setMethods(array( // 'fetch' // ))->getMock(); // $oMockView->expects($this->any())->method('fetch')->will($this->returnValue('content')); // Config::set('default_return_type', "html"); // $result = Response::error($msg, $data, $url); // FIXME 静态方法mock // $this->assertEquals('content', $result); }
/** * 操作错误跳转的快捷方法 * @access public * @param mixed $msg 提示信息 * @param mixed $data 返回的数据 * @param mixed $url 跳转的URL地址 * @param mixed $wait 跳转等待时间 * @return void */ public function error($msg = '', $data = '', $url = '', $wait = 3) { return Response::error($msg, $data, $url, $wait); }
private function error($msg = '', $data = '', $url = '', $wait = 3) { echo Response::error($msg, $data, $url, $wait); die; }