-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bridge/Monolog] Fix WebProcessor to accept a Request object.
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
tests/Symfony/Tests/Bridge/Monolog/Processor/WebProcessorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Bridge\Monolog\Processor; | ||
|
||
use Monolog\Logger; | ||
use Symfony\Bridge\Monolog\Processor\WebProcessor; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class WebProcessorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testUsesRequestServerData() | ||
{ | ||
$server = array( | ||
'REQUEST_URI' => 'A', | ||
'REMOTE_ADDR' => 'B', | ||
'REQUEST_METHOD' => 'C', | ||
); | ||
|
||
$request = new Request(); | ||
$request->server->replace($server); | ||
|
||
$processor = new WebProcessor($request); | ||
$record = $processor($this->getRecord()); | ||
|
||
$this->assertEquals($server['REQUEST_URI'], $record['extra']['url']); | ||
$this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']); | ||
$this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']); | ||
} | ||
|
||
/** | ||
* @return array Record | ||
*/ | ||
protected function getRecord($level = Logger::WARNING, $message = 'test') | ||
{ | ||
return array( | ||
'message' => $message, | ||
'context' => array(), | ||
'level' => $level, | ||
'level_name' => Logger::getLevelName($level), | ||
'channel' => 'test', | ||
'datetime' => new \DateTime(), | ||
'extra' => array(), | ||
); | ||
} | ||
} |