public function testQuotePhpArguments() { $this->assertSame("'hello', 'hi'", ShellUtils::quotePhpArguments(['hello', 'hi'])); $this->assertSame("'hello', array(0 => 'hi', 1 => 'hi2')", ShellUtils::quotePhpArguments(['hello', ['hi', 'hi2']])); $this->assertSame("546", ShellUtils::quotePhpArgument(546)); $this->assertSame("true", ShellUtils::quotePhpArgument(true)); $this->assertSame("false", ShellUtils::quotePhpArgument(false)); $this->assertSame("54.23", ShellUtils::quotePhpArgument(54.23)); $this->assertSame("null", ShellUtils::quotePhpArgument(null)); }
/** * Creates stack trace with custom formatting from supplied exception. * @param Exception $e * @return string stack trace */ protected static function getCustomTrace(Exception $e) { $trace = array(); $index = 0; $defaults = array('file' => null, 'line' => null, 'class' => null, 'function' => null, 'type' => '::', 'args' => array()); foreach ($e->getTrace() as $props) { $props = array_merge($defaults, $props); $location = $props['file'] ? $props['file'] != 'Command line code' ? basename($props['file']) . ':' . $props['line'] : '[command line]' : '[unknown location]'; if ($props['function'] == 'trigger_error' && $props['class'] === null) { $trace[] = "User error triggered ({$location}): {$props['args'][0]}"; } elseif ($props['class'] == 'Utils' && $props['function'] == 'turnErrorToException' || $props['class'] == 'ErrorHandler' && $props['function'] == 'handleException' || $props['class'] == 'ErrorHandler' && $props['function'] == 'handleError') { continue; } else { $arguments = ShellUtils::quotePhpArguments($props['args']); $function = $props['function'] ? "{$props['function']}({$arguments})" : ''; $caller = $function && $props['class'] ? $props['class'] : ''; $call = $caller ? $props['type'] : ''; $trace[] = "#{$index} {$location} {$caller}{$call}{$function}"; ++$index; } } return implode("\n", $trace); }