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 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
<?php declare(strict_types=1);
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Level;
/**
* @covers Monolog\Handler\FirePHPHandler
*/
class FirePHPHandlerTest extends \Monolog\Test\MonologTestCase
{
public function setUp(): void
{
TestFirePHPHandler::resetStatic();
$_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; FirePHP/1.0';
}
public function testHeaders()
{
$handler = new TestFirePHPHandler;
$handler->setFormatter($this->getIdentityFormatter());
$handler->handle($this->getRecord(Level::Debug));
$handler->handle($this->getRecord(Level::Warning));
$expected = [
'X-Wf-Protocol-1' => 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2',
'X-Wf-1-Structure-1' => 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1',
'X-Wf-1-Plugin-1' => 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3',
'X-Wf-1-1-1-1' => 'test',
'X-Wf-1-1-1-2' => 'test',
];
$this->assertEquals($expected, $handler->getHeaders());
}
public function testConcurrentHandlers()
{
$handler = new TestFirePHPHandler;
$handler->setFormatter($this->getIdentityFormatter());
$handler->handle($this->getRecord(Level::Debug));
$handler->handle($this->getRecord(Level::Warning));
$handler2 = new TestFirePHPHandler;
$handler2->setFormatter($this->getIdentityFormatter());
$handler2->handle($this->getRecord(Level::Debug));
$handler2->handle($this->getRecord(Level::Warning));
$expected = [
'X-Wf-Protocol-1' => 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2',
'X-Wf-1-Structure-1' => 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1',
'X-Wf-1-Plugin-1' => 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3',
'X-Wf-1-1-1-1' => 'test',
'X-Wf-1-1-1-2' => 'test',
];
$expected2 = [
'X-Wf-1-1-1-3' => 'test',
'X-Wf-1-1-1-4' => 'test',
];
$this->assertEquals($expected, $handler->getHeaders());
$this->assertEquals($expected2, $handler2->getHeaders());
}
}
class TestFirePHPHandler extends FirePHPHandler
{
protected array $headers = [];
public static function resetStatic(): void
{
self::$initialized = false;
self::$sendHeaders = true;
self::$messageIndex = 1;
}
protected function sendHeader(string $header, string $content): void
{
$this->headers[$header] = $content;
}
public function getHeaders(): array
{
return $this->headers;
}
protected function isWebRequest(): bool
{
return true;
}
}
|