18use PhpConsole\Connector;
19use PhpConsole\Dispatcher\Debug as DebugDispatcher;
20use PhpConsole\Dispatcher\Errors as ErrorDispatcher;
21use PhpConsole\Handler;
22use PHPUnit_Framework_MockObject_MockObject;
39 if (!class_exists(
'PhpConsole\Connector')) {
40 $this->markTestSkipped(
'PHP Console library not found. See https://github.com/barbushin/php-console#installation');
45 $this->connector->setDebugDispatcher($this->debugDispatcher);
48 $this->connector->setErrorsDispatcher($this->errorDispatcher);
53 return $this->getMockBuilder(
'PhpConsole\Dispatcher\Debug')
54 ->disableOriginalConstructor()
55 ->setMethods(array(
'dispatchDebug'))
62 return $this->getMockBuilder(
'PhpConsole\Dispatcher\Errors')
63 ->disableOriginalConstructor()
64 ->setMethods(array(
'dispatchError',
'dispatchException'))
71 $connector = $this->getMockBuilder(
'PhpConsole\Connector')
72 ->disableOriginalConstructor()
83 'startEvalRequestsListener',
88 ->method(
'isActiveClient')
89 ->will($this->returnValue(
true));
104 return new Logger(
'test', array(
112 $this->assertEquals(spl_object_hash(Connector::getInstance()), spl_object_hash($handler->getConnector()));
118 $this->assertEquals(spl_object_hash($this->connector), spl_object_hash($handler->getConnector()));
123 $this->debugDispatcher->expects($this->once())->method(
'dispatchDebug')->with($this->equalTo(
'test'));
131 $context = array($tag,
'custom' => mt_rand());
132 $expectedMessage = $message .
' ' . json_encode(array_slice($context, 1));
133 $this->debugDispatcher->expects($this->once())->method(
'dispatchDebug')->with(
134 $this->equalTo($expectedMessage),
137 $this->
initLogger()->addDebug($message, $context);
142 $expectedTags = mt_rand();
143 $logger = $this->
initLogger($tagsContextKeys ? array(
'debugTagsKeysInContext' => $tagsContextKeys) : array());
144 if (!$tagsContextKeys) {
147 foreach ($tagsContextKeys as $key) {
151 $this->equalTo($expectedTags)
154 $logger->addDebug(
'test', array($key => $expectedTags));
158 public function testError($classesPartialsTraceIgnore =
null)
160 $code = E_USER_NOTICE;
161 $message =
'message';
164 $this->errorDispatcher->expects($this->once())->method(
'dispatchError')->with(
165 $this->equalTo(
$code),
166 $this->equalTo($message),
167 $this->equalTo(
$file),
168 $this->equalTo($line),
171 $errorHandler =
ErrorHandler::register($this->
initLogger($classesPartialsTraceIgnore ? array(
'classesPartialsTraceIgnore' => $classesPartialsTraceIgnore) : array()),
false);
172 $errorHandler->registerErrorHandler(array(),
false, E_USER_WARNING);
173 $errorHandler->handleError(
$code, $message,
$file, $line);
178 $e =
new Exception();
179 $this->errorDispatcher->expects($this->once())->method(
'dispatchException')->with(
185 sprintf(
'Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
186 array(
'exception' => $e)
200 $this->debugDispatcher->expects($this->never())->method(
'dispatchDebug');
201 $this->
initLogger(array(
'enabled' =>
false))->addDebug(
'test');
206 $this->
testError(array(
'Class',
'Namespace\\'));
216 $this->
initLogger(array(
'useOwnErrorsHandler' =>
true,
'useOwnExceptionsHandler' =>
true));
217 $this->assertEquals(array(Handler::getInstance(),
'handleError'), set_error_handler(
function () {
219 $this->assertEquals(array(Handler::getInstance(),
'handleException'), set_exception_handler(
function () {
226 array(
'sourcesBasePath',
'setSourcesBasePath', __DIR__),
227 array(
'serverEncoding',
'setServerEncoding',
'cp1251'),
228 array(
'password',
'setPassword',
'******'),
229 array(
'enableSslOnlyMode',
'enableSslOnlyMode',
true,
false),
230 array(
'ipMasks',
'setAllowedIpMasks', array(
'127.0.0.*')),
231 array(
'headersLimit',
'setHeadersLimit', 2500),
232 array(
'enableEvalListener',
'startEvalRequestsListener',
true,
false),
241 $expectCall = $this->connector->expects($this->once())->method($method);
243 $expectCall->with($value);
250 new PHPConsoleHandler(array(
'detectDumpTraceAndSource' =>
true), $this->connector);
251 $this->assertTrue($this->connector->getDebugDispatcher()->detectTraceAndSource);
257 array(
'dumperLevelLimit',
'levelLimit', 1001),
258 array(
'dumperItemsCountLimit',
'itemsCountLimit', 1002),
259 array(
'dumperItemSizeLimit',
'itemSizeLimit', 1003),
260 array(
'dumperDumpSizeLimit',
'dumpSizeLimit', 1004),
261 array(
'dumperDetectCallbacks',
'detectCallbacks',
true),
271 $this->assertEquals($value, $this->connector->getDumper()->$dumperProperty);
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
static register(LoggerInterface $logger, $errorLevelMap=array(), $exceptionLevel=null, $fatalLevel=null)
Registers a new ErrorHandler for a given Logger.
@covers Monolog\Handler\PHPConsoleHandler
initDebugDispatcherMock(Connector $connector)
testOptionDetectDumpTraceAndSource()
testDebugContextInMessage()
testWrongOptionsThrowsException()
@expectedException Exception
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
testOptionUseOwnErrorsAndExceptionsHandler()
static provideConnectorMethodsOptionsSets()
testDumperOptions($option, $dumperProperty, $value)
@dataProvider provideDumperOptionsValues
testOptionDebugTagsKeysInContext()
getHandlerDefaultOption($name)
testInitWithDefaultConnector()
testError($classesPartialsTraceIgnore=null)
testOptionClassesPartialsTraceIgnore()
initErrorDispatcherMock(Connector $connector)
static provideDumperOptionsValues()
testInitWithCustomConnector()
testOptionCallsConnectorMethod($option, $method, $value, $isArgument=true)
@dataProvider provideConnectorMethodsOptionsSets
testDebugTags($tagsContextKeys=null)
Monolog handler for Google Chrome extension "PHP Console".
const DEBUG
Detailed debug information.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
if(!is_array($argv)) $options