public function testRun()
{
$this->given($pusher = new testedClass(__FILE__), $pusher->setTaggerEngine($taggerEngine = new \mock\mageekguy\atoum\scripts\tagger\engine()), $pusher->setGit($git = new \mock\mageekguy\atoum\cli\commands\git()), $pusher->setErrorWriter($errorWriter = new \mock\mageekguy\atoum\writers\std\err()), $pusher->setInfoWriter($infoWriter = new \mock\mageekguy\atoum\writers\std\out()), $this->calling($infoWriter)->write = $infoWriter)->assert('Pusher should write error if tag file is not readable')->if($this->calling($errorWriter)->write = $errorWriter, $this->function->file_get_contents = false)->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments('Unable to read \'' . $pusher->getTagFile() . '\'')->once()->assert('Pusher should write error if tag file is not writable')->if($this->calling($errorWriter)->write = $errorWriter, $this->function->file_put_contents = false, $this->function->file_get_contents = '0.0.0')->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments('Unable to write in \'' . $pusher->getTagFile() . '\'')->once()->assert('Pusher should tag code and commit it if tag file is writable')->if($this->function->file_put_contents = function ($path, $data) {
return strlen($data);
}, $this->calling($taggerEngine)->tagVersion->doesNothing(), $this->calling($git)->addAllAndCommit = $git, $this->calling($git)->checkoutAllFiles = $git, $this->calling($git)->createTag = $git, $this->calling($git)->push = $git, $this->calling($git)->forcePush = $git, $this->calling($git)->pushTag = $git, $this->calling($git)->resetHardTo = $git, $this->calling($git)->deleteLocalTag = $git)->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '0.0.1')->once()->mock($taggerEngine)->call('tagVersion')->before($this->mock($git)->call('addAllAndCommit')->withArguments('Set version to 0.0.1.')->before($this->mock($git)->call('createTag')->withArguments('0.0.1')->before($this->mock($git)->call('push')->withArguments($pusher->getRemote())->once())->before($this->mock($git)->call('pushTag')->withArguments('0.0.1', $pusher->getRemote())->once())->once())->once())->after($this->mock($taggerEngine)->call('setSrcDirectory')->withArguments($pusher->getWorkingDirectory())->once())->after($this->mock($taggerEngine)->call('setVersion')->withArguments('$Rev:' . ' 0.0.1 $')->once())->once()->call('tagVersion')->before($this->mock($git)->call('addAllAndCommit')->withArguments('Set version to dev-master.')->once())->after($this->mock($taggerEngine)->call('setSrcDirectory')->withArguments($pusher->getWorkingDirectory())->once())->after($this->mock($taggerEngine)->call('setVersion')->withArguments('$Rev:' . ' dev-master $')->once())->once()->if($pusher->tagPatchVersion())->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '0.0.1')->twice()->if($pusher->tagMinorVersion())->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '0.1.0')->once()->if($pusher->tagMajorVersion())->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '1.0.0')->once()->assert('Pusher should write error if pushing tag failed and should try to reset repository')->if($pusher->tagPatchVersion(), $this->calling($git)->pushTag->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~2')->once()->call('deleteLocalTag')->withArguments('0.0.1')->once()->assert('Pusher should write error if pushing commit failed and should try to reset repository')->if($this->calling($git)->push->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~2')->once()->call('deleteLocalTag')->withArguments('0.0.1')->once()->assert('Pusher should write error if pushing commit for DEVELOPMENT version failed and should try to reset repository')->if($this->calling($git)->push = $git, $this->calling($git)->addAllAndCommit[2]->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~1')->once()->assert('Pusher should write error if pushing commit for DEVELOPMENT version failed and should try to reset repository')->if($this->calling($git)->createTag->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~1')->once()->assert('Pusher should write error if commit failed for STABLE version and should try to reset repository')->if($this->calling($git)->createTag = $git, $this->calling($git)->addAllAndCommit[1]->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->after($this->mock($git)->call('addAllAndCommit'))->once()->mock($git)->call('checkoutAllFiles')->after($this->mock($git)->call('addAllAndCommit'))->once()->assert('Pusher should write error if reset failed')->if($this->calling($git)->checkoutAllFiles->throw = $checkoutAllFilesException = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($checkoutAllFilesException->getMessage())->once();
}
开发者ID:xihewang,项目名称:atoum,代码行数:6,代码来源:pusher.php
示例8: send_error
/**
* Send the error information to the WS client
* formatted as XML document.
* @param exception $ex
* @return void
*/
protected function send_error($ex = null)
{
// Zend Soap server fault handling is incomplete compared to XML-RPC :-(
// we can not use: echo $this->zend_server->fault($ex);
//TODO: send some better response in XML
if ($ex) {
$info = $ex->getMessage();
if (debugging() and isset($ex->debuginfo)) {
$info .= ' - ' . $ex->debuginfo;
}
} else {
$info = 'Unknown error';
}
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body><SOAP-ENV:Fault>
<faultcode>MOODLE:error</faultcode>
<faultstring>' . $info . '</faultstring>
</SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>';
$this->send_headers();
header('Content-Type: application/xml; charset=utf-8');
header('Content-Disposition: inline; filename="response.xml"');
echo $xml;
}
/**
* Displays an exception in HTML, and exists. Includes the exception
* trace in an HTML comment, and a readable error string along with the
* exception message.
* @param exception $e Exception
*/
public static function handle_exception($e)
{
// Display actual trace in HTML comment. There shouldn't be any
// security-sensitive information in the trace, so this can be
// displayed even on live server (I hope).
if (debugging('', DEBUG_DEVELOPER)) {
global $CFG;
print "<pre class='forumng-stacktrace'>";
print htmlspecialchars(str_replace($CFG->dirroot, '', $e->getTraceAsString()));
print "</pre>";
} else {
print "<!--\n";
print $e->getTraceAsString();
// Not escaped, I think this is correct...
print "\n-->";
}
// Make a short version of the trace string for log
$minitrace = self::get_minitrace_part($e->getFile(), $e->getLine());
foreach ($e->getTrace() as $entry) {
$minitrace .= ' ' . self::get_minitrace_part($entry['file'], $entry['line']);
}
$minitrace = shorten_text($minitrace, 120, true);
$message = shorten_text($e->getMessage(), 120, true);
global $FULLME, $USER, $CFG;
$url = str_replace($CFG->wwwroot . '/mod/forumng/', '', $FULLME);
add_to_log(0, 'forumng', 'error', $url, "{$message} / {$minitrace}", 0, $USER->id);
// Error to user with just the message
print_error('error_exception', 'forumng', '', $e->getMessage());
}
/**
* adds a exception to the array of displayed exceptions for the view
* by default is displayed in the inc_header, but with the custom destination set to true
* the exception won't be displayed by default but can be displayed where ever wanted in the tpl
*
* @param exception $oEr a exception object or just a language local (string) which will be converted into a oxExceptionToDisplay object
* @param bool $blFull if true the whole object is add to display (default false)
* @param bool $blCustomDestination true if the exception shouldn't be displayed at the default position (default false)
* @param string $sCustomDestination defines a name of the view variable containing the messages, overrides Parameter 'CustomError' ("default")
* @param string $sActiveController defines a name of the controller, which should handle the error.
*/
public function addErrorToDisplay($oEr, $blFull = false, $blCustomDestination = false, $sCustomDestination = "", $sActiveController = "")
{
if ($blCustomDestination && (oxRegistry::getConfig()->getRequestParameter('CustomError') || $sCustomDestination != '')) {
// check if the current request wants do display exceptions on its own
$sDestination = oxRegistry::getConfig()->getRequestParameter('CustomError');
if ($sCustomDestination != '') {
$sDestination = $sCustomDestination;
}
} else {
//default
$sDestination = 'default';
}
//starting session if not yet started as all exception
//messages are stored in session
$oSession = $this->getSession();
if (!$oSession->getId() && !$oSession->isHeaderSent()) {
$oSession->setForceNewSession();
$oSession->start();
}
$aEx = oxRegistry::getSession()->getVariable('Errors');
if ($oEr instanceof oxException) {
$oEx = oxNew('oxExceptionToDisplay');
$oEx->setMessage($oEr->getMessage());
$oEx->setExceptionType(get_class($oEr));
if ($oEr instanceof oxSystemComponentException) {
$oEx->setMessageArgs($oEr->getComponent());
}
$oEx->setValues($oEr->getValues());
$oEx->setStackTrace($oEr->getTraceAsString());
$oEx->setDebug($blFull);
$oEr = $oEx;
} elseif ($oEr && !$oEr instanceof oxIDisplayError) {
// assuming that a string was given
$sTmp = $oEr;
$oEr = oxNew('oxDisplayError');
$oEr->setMessage($sTmp);
} elseif ($oEr instanceof oxIDisplayError) {
// take the object
} else {
$oEr = null;
}
if ($oEr) {
$aEx[$sDestination][] = serialize($oEr);
oxRegistry::getSession()->setVariable('Errors', $aEx);
if ($sActiveController == '') {
$sActiveController = oxRegistry::getConfig()->getRequestParameter('actcontrol');
}
if ($sActiveController) {
$aControllerErrors[$sDestination] = $sActiveController;
oxRegistry::getSession()->setVariable('ErrorController', $aControllerErrors);
}
}
}
请发表评论