1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?php
namespace PhpConsole\Test;
class PsrLogger extends \Psr\Log\Test\LoggerInterfaceTest {
/** @var \PhpConsole\Connector|\PHPUnit_Framework_MockObject_MockObject */ protected $connector; /** @var \PhpConsole\ErrorMessage[]|\PhpConsole\DebugMessage[] */ public $sentMessages = array();
protected function setUp() { parent::setUp(); $this->connector = $this->initConnectorMock(); $this->sentMessages = array(); }
protected function initConnectorMock() { $connector = $this->getMockBuilder('\PhpConsole\Connector') ->disableOriginalConstructor() ->setMethods(array('sendMessage', 'isActiveClient')) ->getMock();
$connector->expects($this->any()) ->method('isActiveClient') ->will($this->returnValue(true));
$test = $this; $connector->expects($this->any()) ->method('sendMessage') ->will($this->returnCallback(function (\PhpConsole\Message $message) use ($test) { $test->sentMessages[] = $message; }));
return $connector; }
/** * @return \Psr\Log\LoggerInterface */ function getLogger() { return new \PhpConsole\PsrLogger($this->connector); }
/** * This must return the log messages in order with a simple formatting: "<LOG LEVEL> <MESSAGE>" * * Example ->error('Foo') would yield "error Foo" * * @return string[] */ function getLogs() { $messagesData = array(); foreach($this->sentMessages as $message) { if($message instanceof \PhpConsole\ErrorMessage) { $messagesData[] = array_search($message->class, \PhpConsole\PsrLogger::$errorsLevels) . ' ' . $message->data; } elseif($message instanceof \PhpConsole\DebugMessage) { $messagesData[] = array_search($message->tags[0], \PhpConsole\PsrLogger::$debugLevels) . ' ' . $message->data; } } return $messagesData; }
public function testContextDataIsDumped() { /** @var \PhpConsole\Dumper $dumper */ $dumper = $this->connector->getDumper(); $string = str_repeat('x', $dumper->itemSizeLimit + 1); $this->getLogger()->info('{var}', array('var' => $string)); $messagesData = $this->getLogs(); $this->assertEquals('info ' . $dumper->dump($string), $messagesData[0]); }
public function testExceptionContextVarIsDispatched() { $this->getLogger()->critical('error', array('exception' => new \Exception('exception message'))); $this->assertEquals(1, count($this->sentMessages)); /** @var \PhpConsole\ErrorMessage $message */ $message = $this->sentMessages[0]; $this->assertInstanceOf('PhpConsole\ErrorMessage', $message); $message->data = 'exception message'; }
public function testContextExceptionKeyCanBeExceptionOrOtherValues() { $this->markTestSkipped('Stupid PSR issue that will not be implemented in PHP Console'); } }
|