19 use PhpConsole\Dispatcher\Debug as DebugDispatcher;
20 use PhpConsole\Dispatcher\Errors as ErrorDispatcher;
40 if (!class_exists(
'PhpConsole\Connector')) {
41 $this->markTestSkipped(
'PHP Console library not found. See https://github.com/barbushin/php-console#installation');
46 $this->connector->setDebugDispatcher($this->debugDispatcher);
49 $this->connector->setErrorsDispatcher($this->errorDispatcher);
54 return $this->getMockBuilder(
'PhpConsole\Dispatcher\Debug')
55 ->disableOriginalConstructor()
56 ->setMethods(array(
'dispatchDebug'))
57 ->setConstructorArgs(array($connector, $connector->getDumper()))
63 return $this->getMockBuilder(
'PhpConsole\Dispatcher\Errors')
64 ->disableOriginalConstructor()
65 ->setMethods(array(
'dispatchError',
'dispatchException'))
66 ->setConstructorArgs(array($connector, $connector->getDumper()))
72 $connector = $this->getMockBuilder(
'PhpConsole\Connector')
73 ->disableOriginalConstructor()
84 'startEvalRequestsListener',
89 ->method(
'isActiveClient')
90 ->will($this->returnValue(
true));
105 return new Logger(
'test', array(
113 $this->assertEquals(spl_object_hash(Connector::getInstance()), spl_object_hash($handler->getConnector()));
119 $this->assertEquals(spl_object_hash($this->connector), spl_object_hash($handler->getConnector()));
124 $this->debugDispatcher->expects($this->once())->method(
'dispatchDebug')->with($this->equalTo(
'test'));
132 $context = array($tag,
'custom' => mt_rand());
133 $expectedMessage = $message .
' ' . json_encode(array_slice($context, 1));
134 $this->debugDispatcher->expects($this->once())->method(
'dispatchDebug')->with(
135 $this->equalTo($expectedMessage),
138 $this->
initLogger()->addDebug($message, $context);
143 $expectedTags = mt_rand();
144 $logger = $this->
initLogger($tagsContextKeys ? array(
'debugTagsKeysInContext' => $tagsContextKeys) : array());
145 if (!$tagsContextKeys) {
148 foreach ($tagsContextKeys as $key) {
152 $this->equalTo($expectedTags)
155 $logger->addDebug(
'test', array($key => $expectedTags));
159 public function testError($classesPartialsTraceIgnore = null)
161 $code = E_USER_NOTICE;
162 $message =
'message';
165 $this->errorDispatcher->expects($this->once())->method(
'dispatchError')->with(
166 $this->equalTo(
$code),
167 $this->equalTo($message),
168 $this->equalTo(
$file),
169 $this->equalTo($line),
172 $errorHandler =
ErrorHandler::register($this->
initLogger($classesPartialsTraceIgnore ? array(
'classesPartialsTraceIgnore' => $classesPartialsTraceIgnore) : array()),
false);
173 $errorHandler->registerErrorHandler(array(),
false, E_USER_WARNING);
174 $errorHandler->handleError(
$code, $message,
$file, $line);
180 $this->errorDispatcher->expects($this->once())->method(
'dispatchException')->with(
186 sprintf(
'Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
187 array(
'exception' => $e)
201 $this->debugDispatcher->expects($this->never())->method(
'dispatchDebug');
202 $this->
initLogger(array(
'enabled' =>
false))->addDebug(
'test');
207 $this->
testError(array(
'Class',
'Namespace\\'));
217 $this->
initLogger(array(
'useOwnErrorsHandler' =>
true,
'useOwnExceptionsHandler' =>
true));
218 $this->assertEquals(array(Handler::getInstance(),
'handleError'), set_error_handler(
function () {
220 $this->assertEquals(array(Handler::getInstance(),
'handleException'), set_exception_handler(
function () {
227 array(
'sourcesBasePath',
'setSourcesBasePath', __DIR__),
228 array(
'serverEncoding',
'setServerEncoding',
'cp1251'),
229 array(
'password',
'setPassword',
'******'),
230 array(
'enableSslOnlyMode',
'enableSslOnlyMode',
true,
false),
231 array(
'ipMasks',
'setAllowedIpMasks', array(
'127.0.0.*')),
232 array(
'headersLimit',
'setHeadersLimit', 2500),
233 array(
'enableEvalListener',
'startEvalRequestsListener',
true,
false),
242 $expectCall = $this->connector->expects($this->once())->method($method);
244 $expectCall->with($value);
251 new PHPConsoleHandler(array(
'detectDumpTraceAndSource' =>
true), $this->connector);
252 $this->assertTrue($this->connector->getDebugDispatcher()->detectTraceAndSource);
258 array(
'dumperLevelLimit',
'levelLimit', 1001),
259 array(
'dumperItemsCountLimit',
'itemsCountLimit', 1002),
260 array(
'dumperItemSizeLimit',
'itemSizeLimit', 1003),
261 array(
'dumperDumpSizeLimit',
'dumpSizeLimit', 1004),
262 array(
'dumperDetectCallbacks',
'detectCallbacks',
true),
272 $this->assertEquals($value, $this->connector->getDumper()->$dumperProperty);
testDebugTags($tagsContextKeys=null)
const DEBUG
Detailed debug information.
testWrongOptionsThrowsException()
Exception
static provideConnectorMethodsOptionsSets()
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
testDebugContextInMessage()
initDebugDispatcherMock(Connector $connector)
testError($classesPartialsTraceIgnore=null)
Monolog handler for Google Chrome extension "PHP Console".
testInitWithDefaultConnector()
testOptionCallsConnectorMethod($option, $method, $value, $isArgument=true)
provideConnectorMethodsOptionsSets
if(!is_array($argv)) $options
testOptionUseOwnErrorsAndExceptionsHandler()
static provideDumperOptionsValues()
testOptionDetectDumpTraceAndSource()
testDumperOptions($option, $dumperProperty, $value)
provideDumperOptionsValues
testOptionClassesPartialsTraceIgnore()
static register(LoggerInterface $logger, $errorLevelMap=array(), $exceptionLevel=null, $fatalLevel=null)
Registers a new ErrorHandler for a given Logger.
getHandlerDefaultOption($name)
testOptionDebugTagsKeysInContext()
initErrorDispatcherMock(Connector $connector)
testInitWithCustomConnector()