ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Handler\PHPConsoleHandlerTest Class Reference

Monolog More...

+ Inheritance diagram for Monolog\Handler\PHPConsoleHandlerTest:
+ Collaboration diagram for Monolog\Handler\PHPConsoleHandlerTest:

Public Member Functions

 testInitWithDefaultConnector ()
 
 testInitWithCustomConnector ()
 
 testDebug ()
 
 testDebugContextInMessage ()
 
 testDebugTags ($tagsContextKeys=null)
 
 testError ($classesPartialsTraceIgnore=null)
 
 testException ()
 
 testWrongOptionsThrowsException ()
 Exception More...
 
 testOptionEnabled ()
 
 testOptionClassesPartialsTraceIgnore ()
 
 testOptionDebugTagsKeysInContext ()
 
 testOptionUseOwnErrorsAndExceptionsHandler ()
 
 testOptionCallsConnectorMethod ($option, $method, $value, $isArgument=true)
 provideConnectorMethodsOptionsSets More...
 
 testOptionDetectDumpTraceAndSource ()
 
 testDumperOptions ($option, $dumperProperty, $value)
 provideDumperOptionsValues More...
 

Static Public Member Functions

static provideConnectorMethodsOptionsSets ()
 
static provideDumperOptionsValues ()
 

Protected Member Functions

 setUp ()
 
 initDebugDispatcherMock (Connector $connector)
 
 initErrorDispatcherMock (Connector $connector)
 
 initConnectorMock ()
 
 getHandlerDefaultOption ($name)
 
 initLogger ($handlerOptions=array(), $level=Logger::DEBUG)
 
- Protected Member Functions inherited from Monolog\TestCase
 getRecord ($level=Logger::WARNING, $message='test', $context=array())
 
 getMultipleRecords ()
 
 getIdentityFormatter ()
 

Protected Attributes

 $connector
 
 $debugDispatcher
 
 $errorDispatcher
 

Detailed Description

Monolog

Author
Sergey Barbushin https://www.linkedin.com/in/barbushin

Definition at line 28 of file PHPConsoleHandlerTest.php.

Member Function Documentation

◆ getHandlerDefaultOption()

Monolog\Handler\PHPConsoleHandlerTest::getHandlerDefaultOption (   $name)
protected

Definition at line 94 of file PHPConsoleHandlerTest.php.

References $handler, $name, and PHPMailer\PHPMailer\$options.

Referenced by Monolog\Handler\PHPConsoleHandlerTest\testDebugTags(), and Monolog\Handler\PHPConsoleHandlerTest\testError().

95  {
96  $handler = new PHPConsoleHandler(array(), $this->connector);
97  $options = $handler->getOptions();
98 
99  return $options[$name];
100  }
$handler
+ Here is the caller graph for this function:

◆ initConnectorMock()

Monolog\Handler\PHPConsoleHandlerTest::initConnectorMock ( )
protected

Definition at line 69 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\$connector.

Referenced by Monolog\Handler\PHPConsoleHandlerTest\setUp().

70  {
71  $connector = $this->getMockBuilder('PhpConsole\Connector')
72  ->disableOriginalConstructor()
73  ->setMethods(array(
74  'sendMessage',
75  'onShutDown',
76  'isActiveClient',
77  'setSourcesBasePath',
78  'setServerEncoding',
79  'setPassword',
80  'enableSslOnlyMode',
81  'setAllowedIpMasks',
82  'setHeadersLimit',
83  'startEvalRequestsListener',
84  ))
85  ->getMock();
86 
87  $connector->expects($this->any())
88  ->method('isActiveClient')
89  ->will($this->returnValue(true));
90 
91  return $connector;
92  }
+ Here is the caller graph for this function:

◆ initDebugDispatcherMock()

Monolog\Handler\PHPConsoleHandlerTest::initDebugDispatcherMock ( Connector  $connector)
protected

Definition at line 51 of file PHPConsoleHandlerTest.php.

Referenced by Monolog\Handler\PHPConsoleHandlerTest\setUp(), and Monolog\Handler\PHPConsoleHandlerTest\testDebugTags().

52  {
53  return $this->getMockBuilder('PhpConsole\Dispatcher\Debug')
54  ->disableOriginalConstructor()
55  ->setMethods(array('dispatchDebug'))
56  ->setConstructorArgs(array($connector, $connector->getDumper()))
57  ->getMock();
58  }
+ Here is the caller graph for this function:

◆ initErrorDispatcherMock()

Monolog\Handler\PHPConsoleHandlerTest::initErrorDispatcherMock ( Connector  $connector)
protected

Definition at line 60 of file PHPConsoleHandlerTest.php.

Referenced by Monolog\Handler\PHPConsoleHandlerTest\setUp().

61  {
62  return $this->getMockBuilder('PhpConsole\Dispatcher\Errors')
63  ->disableOriginalConstructor()
64  ->setMethods(array('dispatchError', 'dispatchException'))
65  ->setConstructorArgs(array($connector, $connector->getDumper()))
66  ->getMock();
67  }
+ Here is the caller graph for this function:

◆ initLogger()

Monolog\Handler\PHPConsoleHandlerTest::initLogger (   $handlerOptions = array(),
  $level = Logger::DEBUG 
)
protected

◆ provideConnectorMethodsOptionsSets()

static Monolog\Handler\PHPConsoleHandlerTest::provideConnectorMethodsOptionsSets ( )
static

Definition at line 223 of file PHPConsoleHandlerTest.php.

224  {
225  return array(
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),
233  );
234  }

◆ provideDumperOptionsValues()

static Monolog\Handler\PHPConsoleHandlerTest::provideDumperOptionsValues ( )
static

Definition at line 254 of file PHPConsoleHandlerTest.php.

255  {
256  return array(
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),
262  );
263  }

◆ setUp()

Monolog\Handler\PHPConsoleHandlerTest::setUp ( )
protected

Definition at line 37 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\initConnectorMock(), Monolog\Handler\PHPConsoleHandlerTest\initDebugDispatcherMock(), and Monolog\Handler\PHPConsoleHandlerTest\initErrorDispatcherMock().

38  {
39  if (!class_exists('PhpConsole\Connector')) {
40  $this->markTestSkipped('PHP Console library not found. See https://github.com/barbushin/php-console#installation');
41  }
42  $this->connector = $this->initConnectorMock();
43 
44  $this->debugDispatcher = $this->initDebugDispatcherMock($this->connector);
45  $this->connector->setDebugDispatcher($this->debugDispatcher);
46 
47  $this->errorDispatcher = $this->initErrorDispatcherMock($this->connector);
48  $this->connector->setErrorsDispatcher($this->errorDispatcher);
49  }
+ Here is the call graph for this function:

◆ testDebug()

Monolog\Handler\PHPConsoleHandlerTest::testDebug ( )

Definition at line 121 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\initLogger(), and Sabre\Event\once().

122  {
123  $this->debugDispatcher->expects($this->once())->method('dispatchDebug')->with($this->equalTo('test'));
124  $this->initLogger()->addDebug('test');
125  }
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testDebugContextInMessage()

Monolog\Handler\PHPConsoleHandlerTest::testDebugContextInMessage ( )

Definition at line 127 of file PHPConsoleHandlerTest.php.

References $context, $message, $tag, Monolog\Handler\PHPConsoleHandlerTest\initLogger(), and Sabre\Event\once().

128  {
129  $message = 'test';
130  $tag = 'tag';
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),
135  $this->equalTo($tag)
136  );
137  $this->initLogger()->addDebug($message, $context);
138  }
$context
Definition: webdav.php:25
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
catch(Exception $e) $message
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
if(function_exists('posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35
+ Here is the call graph for this function:

◆ testDebugTags()

Monolog\Handler\PHPConsoleHandlerTest::testDebugTags (   $tagsContextKeys = null)

Definition at line 140 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\$debugDispatcher, $key, Monolog\Handler\PHPConsoleHandlerTest\getHandlerDefaultOption(), Monolog\Handler\PHPConsoleHandlerTest\initDebugDispatcherMock(), Monolog\Handler\PHPConsoleHandlerTest\initLogger(), and Sabre\Event\once().

Referenced by Monolog\Handler\PHPConsoleHandlerTest\testOptionDebugTagsKeysInContext().

141  {
142  $expectedTags = mt_rand();
143  $logger = $this->initLogger($tagsContextKeys ? array('debugTagsKeysInContext' => $tagsContextKeys) : array());
144  if (!$tagsContextKeys) {
145  $tagsContextKeys = $this->getHandlerDefaultOption('debugTagsKeysInContext');
146  }
147  foreach ($tagsContextKeys as $key) {
148  $debugDispatcher = $this->initDebugDispatcherMock($this->connector);
149  $debugDispatcher->expects($this->once())->method('dispatchDebug')->with(
150  $this->anything(),
151  $this->equalTo($expectedTags)
152  );
153  $this->connector->setDebugDispatcher($debugDispatcher);
154  $logger->addDebug('test', array($key => $expectedTags));
155  }
156  }
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDumperOptions()

Monolog\Handler\PHPConsoleHandlerTest::testDumperOptions (   $option,
  $dumperProperty,
  $value 
)

provideDumperOptionsValues

Definition at line 268 of file PHPConsoleHandlerTest.php.

269  {
270  new PHPConsoleHandler(array($option => $value), $this->connector);
271  $this->assertEquals($value, $this->connector->getDumper()->$dumperProperty);
272  }

◆ testError()

Monolog\Handler\PHPConsoleHandlerTest::testError (   $classesPartialsTraceIgnore = null)

Definition at line 158 of file PHPConsoleHandlerTest.php.

References $code, $message, Monolog\Handler\PHPConsoleHandlerTest\getHandlerDefaultOption(), Monolog\Handler\PHPConsoleHandlerTest\initLogger(), Sabre\Event\once(), and Monolog\ErrorHandler\register().

Referenced by Monolog\Handler\PHPConsoleHandlerTest\testOptionClassesPartialsTraceIgnore().

159  {
160  $code = E_USER_NOTICE;
161  $message = 'message';
162  $file = __FILE__;
163  $line = __LINE__;
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),
169  $classesPartialsTraceIgnore ?: $this->equalTo($this->getHandlerDefaultOption('classesPartialsTraceIgnore'))
170  );
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);
174  }
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
$code
Definition: example_050.php:99
catch(Exception $e) $message
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
static register(LoggerInterface $logger, $errorLevelMap=array(), $exceptionLevel=null, $fatalLevel=null)
Registers a new ErrorHandler for a given Logger.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testException()

Monolog\Handler\PHPConsoleHandlerTest::testException ( )

Definition at line 176 of file PHPConsoleHandlerTest.php.

References $handler, Psr\Log\LogLevel\ERROR, Monolog\Handler\PHPConsoleHandlerTest\initLogger(), and Sabre\Event\once().

177  {
178  $e = new Exception();
179  $this->errorDispatcher->expects($this->once())->method('dispatchException')->with(
180  $this->equalTo($e)
181  );
182  $handler = $this->initLogger();
183  $handler->log(
184  \Psr\Log\LogLevel::ERROR,
185  sprintf('Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
186  array('exception' => $e)
187  );
188  }
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$handler
+ Here is the call graph for this function:

◆ testInitWithCustomConnector()

Monolog\Handler\PHPConsoleHandlerTest::testInitWithCustomConnector ( )

Definition at line 115 of file PHPConsoleHandlerTest.php.

References $handler.

116  {
117  $handler = new PHPConsoleHandler(array(), $this->connector);
118  $this->assertEquals(spl_object_hash($this->connector), spl_object_hash($handler->getConnector()));
119  }
$handler

◆ testInitWithDefaultConnector()

Monolog\Handler\PHPConsoleHandlerTest::testInitWithDefaultConnector ( )

Definition at line 109 of file PHPConsoleHandlerTest.php.

References $handler.

110  {
111  $handler = new PHPConsoleHandler();
112  $this->assertEquals(spl_object_hash(Connector::getInstance()), spl_object_hash($handler->getConnector()));
113  }
$handler

◆ testOptionCallsConnectorMethod()

Monolog\Handler\PHPConsoleHandlerTest::testOptionCallsConnectorMethod (   $option,
  $method,
  $value,
  $isArgument = true 
)

provideConnectorMethodsOptionsSets

Definition at line 239 of file PHPConsoleHandlerTest.php.

References Sabre\Event\once().

240  {
241  $expectCall = $this->connector->expects($this->once())->method($method);
242  if ($isArgument) {
243  $expectCall->with($value);
244  }
245  new PHPConsoleHandler(array($option => $value), $this->connector);
246  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testOptionClassesPartialsTraceIgnore()

Monolog\Handler\PHPConsoleHandlerTest::testOptionClassesPartialsTraceIgnore ( )

Definition at line 204 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\testError().

205  {
206  $this->testError(array('Class', 'Namespace\\'));
207  }
testError($classesPartialsTraceIgnore=null)
+ Here is the call graph for this function:

◆ testOptionDebugTagsKeysInContext()

Monolog\Handler\PHPConsoleHandlerTest::testOptionDebugTagsKeysInContext ( )

Definition at line 209 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\testDebugTags().

210  {
211  $this->testDebugTags(array('key1', 'key2'));
212  }
+ Here is the call graph for this function:

◆ testOptionDetectDumpTraceAndSource()

Monolog\Handler\PHPConsoleHandlerTest::testOptionDetectDumpTraceAndSource ( )

Definition at line 248 of file PHPConsoleHandlerTest.php.

249  {
250  new PHPConsoleHandler(array('detectDumpTraceAndSource' => true), $this->connector);
251  $this->assertTrue($this->connector->getDebugDispatcher()->detectTraceAndSource);
252  }

◆ testOptionEnabled()

Monolog\Handler\PHPConsoleHandlerTest::testOptionEnabled ( )

Definition at line 198 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\initLogger().

199  {
200  $this->debugDispatcher->expects($this->never())->method('dispatchDebug');
201  $this->initLogger(array('enabled' => false))->addDebug('test');
202  }
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
+ Here is the call graph for this function:

◆ testOptionUseOwnErrorsAndExceptionsHandler()

Monolog\Handler\PHPConsoleHandlerTest::testOptionUseOwnErrorsAndExceptionsHandler ( )

Definition at line 214 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\initLogger().

215  {
216  $this->initLogger(array('useOwnErrorsHandler' => true, 'useOwnExceptionsHandler' => true));
217  $this->assertEquals(array(Handler::getInstance(), 'handleError'), set_error_handler(function () {
218  }));
219  $this->assertEquals(array(Handler::getInstance(), 'handleException'), set_exception_handler(function () {
220  }));
221  }
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
+ Here is the call graph for this function:

◆ testWrongOptionsThrowsException()

Monolog\Handler\PHPConsoleHandlerTest::testWrongOptionsThrowsException ( )

Exception

Definition at line 193 of file PHPConsoleHandlerTest.php.

194  {
195  new PHPConsoleHandler(array('xxx' => 1));
196  }

Field Documentation

◆ $connector

Monolog\Handler\PHPConsoleHandlerTest::$connector
protected

◆ $debugDispatcher

Monolog\Handler\PHPConsoleHandlerTest::$debugDispatcher
protected

◆ $errorDispatcher

Monolog\Handler\PHPConsoleHandlerTest::$errorDispatcher
protected

Definition at line 35 of file PHPConsoleHandlerTest.php.


The documentation for this class was generated from the following file: