ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 95 of file PHPConsoleHandlerTest.php.

References $options.

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

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

◆ initConnectorMock()

Monolog\Handler\PHPConsoleHandlerTest::initConnectorMock ( )
protected

Definition at line 70 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\$connector.

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

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

◆ initDebugDispatcherMock()

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

Definition at line 52 of file PHPConsoleHandlerTest.php.

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

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

◆ initErrorDispatcherMock()

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

Definition at line 61 of file PHPConsoleHandlerTest.php.

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

62  {
63  return $this->getMockBuilder('PhpConsole\Dispatcher\Errors')
64  ->disableOriginalConstructor()
65  ->setMethods(array('dispatchError', 'dispatchException'))
66  ->setConstructorArgs(array($connector, $connector->getDumper()))
67  ->getMock();
68  }
+ 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 224 of file PHPConsoleHandlerTest.php.

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

◆ provideDumperOptionsValues()

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

Definition at line 255 of file PHPConsoleHandlerTest.php.

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

◆ setUp()

Monolog\Handler\PHPConsoleHandlerTest::setUp ( )
protected

Definition at line 38 of file PHPConsoleHandlerTest.php.

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

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

◆ testDebug()

Monolog\Handler\PHPConsoleHandlerTest::testDebug ( )

Definition at line 122 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\initLogger().

123  {
124  $this->debugDispatcher->expects($this->once())->method('dispatchDebug')->with($this->equalTo('test'));
125  $this->initLogger()->addDebug('test');
126  }
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
+ Here is the call graph for this function:

◆ testDebugContextInMessage()

Monolog\Handler\PHPConsoleHandlerTest::testDebugContextInMessage ( )

Definition at line 128 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\initLogger().

129  {
130  $message = 'test';
131  $tag = 'tag';
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),
136  $this->equalTo($tag)
137  );
138  $this->initLogger()->addDebug($message, $context);
139  }
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
+ Here is the call graph for this function:

◆ testDebugTags()

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

Definition at line 141 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\$debugDispatcher, Monolog\Handler\PHPConsoleHandlerTest\getHandlerDefaultOption(), Monolog\Handler\PHPConsoleHandlerTest\initDebugDispatcherMock(), and Monolog\Handler\PHPConsoleHandlerTest\initLogger().

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

142  {
143  $expectedTags = mt_rand();
144  $logger = $this->initLogger($tagsContextKeys ? array('debugTagsKeysInContext' => $tagsContextKeys) : array());
145  if (!$tagsContextKeys) {
146  $tagsContextKeys = $this->getHandlerDefaultOption('debugTagsKeysInContext');
147  }
148  foreach ($tagsContextKeys as $key) {
149  $debugDispatcher = $this->initDebugDispatcherMock($this->connector);
150  $debugDispatcher->expects($this->once())->method('dispatchDebug')->with(
151  $this->anything(),
152  $this->equalTo($expectedTags)
153  );
154  $this->connector->setDebugDispatcher($debugDispatcher);
155  $logger->addDebug('test', array($key => $expectedTags));
156  }
157  }
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
+ 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 269 of file PHPConsoleHandlerTest.php.

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

◆ testError()

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

Definition at line 159 of file PHPConsoleHandlerTest.php.

References $code, $file, Monolog\Handler\PHPConsoleHandlerTest\getHandlerDefaultOption(), Monolog\Handler\PHPConsoleHandlerTest\initLogger(), and Monolog\ErrorHandler\register().

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

160  {
161  $code = E_USER_NOTICE;
162  $message = 'message';
163  $file = __FILE__;
164  $line = __LINE__;
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),
170  $classesPartialsTraceIgnore ?: $this->equalTo($this->getHandlerDefaultOption('classesPartialsTraceIgnore'))
171  );
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);
175  }
print $file
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
$code
Definition: example_050.php:99
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 177 of file PHPConsoleHandlerTest.php.

References Psr\Log\LogLevel\ERROR, and Monolog\Handler\PHPConsoleHandlerTest\initLogger().

178  {
179  $e = new Exception();
180  $this->errorDispatcher->expects($this->once())->method('dispatchException')->with(
181  $this->equalTo($e)
182  );
183  $handler = $this->initLogger();
184  $handler->log(
186  sprintf('Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
187  array('exception' => $e)
188  );
189  }
initLogger($handlerOptions=array(), $level=Logger::DEBUG)
$Header$
+ Here is the call graph for this function:

◆ testInitWithCustomConnector()

Monolog\Handler\PHPConsoleHandlerTest::testInitWithCustomConnector ( )

Definition at line 116 of file PHPConsoleHandlerTest.php.

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

◆ testInitWithDefaultConnector()

Monolog\Handler\PHPConsoleHandlerTest::testInitWithDefaultConnector ( )

Definition at line 110 of file PHPConsoleHandlerTest.php.

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

◆ testOptionCallsConnectorMethod()

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

provideConnectorMethodsOptionsSets

Definition at line 240 of file PHPConsoleHandlerTest.php.

241  {
242  $expectCall = $this->connector->expects($this->once())->method($method);
243  if ($isArgument) {
244  $expectCall->with($value);
245  }
246  new PHPConsoleHandler(array($option => $value), $this->connector);
247  }

◆ testOptionClassesPartialsTraceIgnore()

Monolog\Handler\PHPConsoleHandlerTest::testOptionClassesPartialsTraceIgnore ( )

Definition at line 205 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\testError().

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

◆ testOptionDebugTagsKeysInContext()

Monolog\Handler\PHPConsoleHandlerTest::testOptionDebugTagsKeysInContext ( )

Definition at line 210 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\testDebugTags().

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

◆ testOptionDetectDumpTraceAndSource()

Monolog\Handler\PHPConsoleHandlerTest::testOptionDetectDumpTraceAndSource ( )

Definition at line 249 of file PHPConsoleHandlerTest.php.

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

◆ testOptionEnabled()

Monolog\Handler\PHPConsoleHandlerTest::testOptionEnabled ( )

Definition at line 199 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\initLogger().

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

◆ testOptionUseOwnErrorsAndExceptionsHandler()

Monolog\Handler\PHPConsoleHandlerTest::testOptionUseOwnErrorsAndExceptionsHandler ( )

Definition at line 215 of file PHPConsoleHandlerTest.php.

References Monolog\Handler\PHPConsoleHandlerTest\initLogger().

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

◆ testWrongOptionsThrowsException()

Monolog\Handler\PHPConsoleHandlerTest::testWrongOptionsThrowsException ( )

Exception

Definition at line 194 of file PHPConsoleHandlerTest.php.

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

Field Documentation

◆ $connector

Monolog\Handler\PHPConsoleHandlerTest::$connector
protected

◆ $debugDispatcher

Monolog\Handler\PHPConsoleHandlerTest::$debugDispatcher
protected

◆ $errorDispatcher

Monolog\Handler\PHPConsoleHandlerTest::$errorDispatcher
protected

Definition at line 36 of file PHPConsoleHandlerTest.php.


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