scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 114  →  ?path2? @ 115
/vendor/monolog/monolog/tests/Monolog/Processor/GitProcessorTest.php
@@ -0,0 +1,29 @@
<?php
 
/*
* 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\Processor;
 
use Monolog\TestCase;
 
class GitProcessorTest extends TestCase
{
/**
* @covers Monolog\Processor\GitProcessor::__invoke
*/
public function testProcessor()
{
$processor = new GitProcessor();
$record = $processor($this->getRecord());
 
$this->assertArrayHasKey('git', $record['extra']);
$this->assertTrue(!is_array($record['extra']['git']['branch']));
}
}
/vendor/monolog/monolog/tests/Monolog/Processor/IntrospectionProcessorTest.php
@@ -0,0 +1,123 @@
<?php
 
/*
* 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 Acme;
 
class Tester
{
public function test($handler, $record)
{
$handler->handle($record);
}
}
 
function tester($handler, $record)
{
$handler->handle($record);
}
 
namespace Monolog\Processor;
 
use Monolog\Logger;
use Monolog\TestCase;
use Monolog\Handler\TestHandler;
 
class IntrospectionProcessorTest extends TestCase
{
public function getHandler()
{
$processor = new IntrospectionProcessor();
$handler = new TestHandler();
$handler->pushProcessor($processor);
 
return $handler;
}
 
public function testProcessorFromClass()
{
$handler = $this->getHandler();
$tester = new \Acme\Tester;
$tester->test($handler, $this->getRecord());
list($record) = $handler->getRecords();
$this->assertEquals(__FILE__, $record['extra']['file']);
$this->assertEquals(18, $record['extra']['line']);
$this->assertEquals('Acme\Tester', $record['extra']['class']);
$this->assertEquals('test', $record['extra']['function']);
}
 
public function testProcessorFromFunc()
{
$handler = $this->getHandler();
\Acme\tester($handler, $this->getRecord());
list($record) = $handler->getRecords();
$this->assertEquals(__FILE__, $record['extra']['file']);
$this->assertEquals(24, $record['extra']['line']);
$this->assertEquals(null, $record['extra']['class']);
$this->assertEquals('Acme\tester', $record['extra']['function']);
}
 
public function testLevelTooLow()
{
$input = array(
'level' => Logger::DEBUG,
'extra' => array(),
);
 
$expected = $input;
 
$processor = new IntrospectionProcessor(Logger::CRITICAL);
$actual = $processor($input);
 
$this->assertEquals($expected, $actual);
}
 
public function testLevelEqual()
{
$input = array(
'level' => Logger::CRITICAL,
'extra' => array(),
);
 
$expected = $input;
$expected['extra'] = array(
'file' => null,
'line' => null,
'class' => 'ReflectionMethod',
'function' => 'invokeArgs',
);
 
$processor = new IntrospectionProcessor(Logger::CRITICAL);
$actual = $processor($input);
 
$this->assertEquals($expected, $actual);
}
 
public function testLevelHigher()
{
$input = array(
'level' => Logger::EMERGENCY,
'extra' => array(),
);
 
$expected = $input;
$expected['extra'] = array(
'file' => null,
'line' => null,
'class' => 'ReflectionMethod',
'function' => 'invokeArgs',
);
 
$processor = new IntrospectionProcessor(Logger::CRITICAL);
$actual = $processor($input);
 
$this->assertEquals($expected, $actual);
}
}
/vendor/monolog/monolog/tests/Monolog/Processor/MemoryPeakUsageProcessorTest.php
@@ -0,0 +1,42 @@
<?php
 
/*
* 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\Processor;
 
use Monolog\TestCase;
 
class MemoryPeakUsageProcessorTest extends TestCase
{
/**
* @covers Monolog\Processor\MemoryPeakUsageProcessor::__invoke
* @covers Monolog\Processor\MemoryProcessor::formatBytes
*/
public function testProcessor()
{
$processor = new MemoryPeakUsageProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('memory_peak_usage', $record['extra']);
$this->assertRegExp('#[0-9.]+ (M|K)?B$#', $record['extra']['memory_peak_usage']);
}
 
/**
* @covers Monolog\Processor\MemoryPeakUsageProcessor::__invoke
* @covers Monolog\Processor\MemoryProcessor::formatBytes
*/
public function testProcessorWithoutFormatting()
{
$processor = new MemoryPeakUsageProcessor(true, false);
$record = $processor($this->getRecord());
$this->assertArrayHasKey('memory_peak_usage', $record['extra']);
$this->assertInternalType('int', $record['extra']['memory_peak_usage']);
$this->assertGreaterThan(0, $record['extra']['memory_peak_usage']);
}
}
/vendor/monolog/monolog/tests/Monolog/Processor/MemoryUsageProcessorTest.php
@@ -0,0 +1,42 @@
<?php
 
/*
* 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\Processor;
 
use Monolog\TestCase;
 
class MemoryUsageProcessorTest extends TestCase
{
/**
* @covers Monolog\Processor\MemoryUsageProcessor::__invoke
* @covers Monolog\Processor\MemoryProcessor::formatBytes
*/
public function testProcessor()
{
$processor = new MemoryUsageProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('memory_usage', $record['extra']);
$this->assertRegExp('#[0-9.]+ (M|K)?B$#', $record['extra']['memory_usage']);
}
 
/**
* @covers Monolog\Processor\MemoryUsageProcessor::__invoke
* @covers Monolog\Processor\MemoryProcessor::formatBytes
*/
public function testProcessorWithoutFormatting()
{
$processor = new MemoryUsageProcessor(true, false);
$record = $processor($this->getRecord());
$this->assertArrayHasKey('memory_usage', $record['extra']);
$this->assertInternalType('int', $record['extra']['memory_usage']);
$this->assertGreaterThan(0, $record['extra']['memory_usage']);
}
}
/vendor/monolog/monolog/tests/Monolog/Processor/MercurialProcessorTest.php
@@ -0,0 +1,41 @@
<?php
 
/*
* This file is part of the Monolog package.
*
* (c) Jonathan A. Schweder <jonathanschweder@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
 
namespace Monolog\Processor;
 
use Monolog\TestCase;
 
class MercurialProcessorTest extends TestCase
{
/**
* @covers Monolog\Processor\MercurialProcessor::__invoke
*/
public function testProcessor()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
exec("where hg 2>NUL", $output, $result);
} else {
exec("which hg 2>/dev/null >/dev/null", $output, $result);
}
if ($result != 0) {
$this->markTestSkipped('hg is missing');
return;
}
 
`hg init`;
$processor = new MercurialProcessor();
$record = $processor($this->getRecord());
 
$this->assertArrayHasKey('hg', $record['extra']);
$this->assertTrue(!is_array($record['extra']['hg']['branch']));
$this->assertTrue(!is_array($record['extra']['hg']['revision']));
}
}
/vendor/monolog/monolog/tests/Monolog/Processor/ProcessIdProcessorTest.php
@@ -0,0 +1,30 @@
<?php
 
/*
* 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\Processor;
 
use Monolog\TestCase;
 
class ProcessIdProcessorTest extends TestCase
{
/**
* @covers Monolog\Processor\ProcessIdProcessor::__invoke
*/
public function testProcessor()
{
$processor = new ProcessIdProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('process_id', $record['extra']);
$this->assertInternalType('int', $record['extra']['process_id']);
$this->assertGreaterThan(0, $record['extra']['process_id']);
$this->assertEquals(getmypid(), $record['extra']['process_id']);
}
}
/vendor/monolog/monolog/tests/Monolog/Processor/PsrLogMessageProcessorTest.php
@@ -0,0 +1,43 @@
<?php
 
/*
* 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\Processor;
 
class PsrLogMessageProcessorTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getPairs
*/
public function testReplacement($val, $expected)
{
$proc = new PsrLogMessageProcessor;
 
$message = $proc(array(
'message' => '{foo}',
'context' => array('foo' => $val),
));
$this->assertEquals($expected, $message['message']);
}
 
public function getPairs()
{
return array(
array('foo', 'foo'),
array('3', '3'),
array(3, '3'),
array(null, ''),
array(true, '1'),
array(false, ''),
array(new \stdClass, '[object stdClass]'),
array(array(), '[array]'),
);
}
}
/vendor/monolog/monolog/tests/Monolog/Processor/TagProcessorTest.php
@@ -0,0 +1,49 @@
<?php
 
/*
* 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\Processor;
 
use Monolog\TestCase;
 
class TagProcessorTest extends TestCase
{
/**
* @covers Monolog\Processor\TagProcessor::__invoke
*/
public function testProcessor()
{
$tags = array(1, 2, 3);
$processor = new TagProcessor($tags);
$record = $processor($this->getRecord());
 
$this->assertEquals($tags, $record['extra']['tags']);
}
 
/**
* @covers Monolog\Processor\TagProcessor::__invoke
*/
public function testProcessorTagModification()
{
$tags = array(1, 2, 3);
$processor = new TagProcessor($tags);
 
$record = $processor($this->getRecord());
$this->assertEquals($tags, $record['extra']['tags']);
 
$processor->setTags(array('a', 'b'));
$record = $processor($this->getRecord());
$this->assertEquals(array('a', 'b'), $record['extra']['tags']);
 
$processor->addTags(array('a', 'c', 'foo' => 'bar'));
$record = $processor($this->getRecord());
$this->assertEquals(array('a', 'b', 'a', 'c', 'foo' => 'bar'), $record['extra']['tags']);
}
}
/vendor/monolog/monolog/tests/Monolog/Processor/UidProcessorTest.php
@@ -0,0 +1,33 @@
<?php
 
/*
* 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\Processor;
 
use Monolog\TestCase;
 
class UidProcessorTest extends TestCase
{
/**
* @covers Monolog\Processor\UidProcessor::__invoke
*/
public function testProcessor()
{
$processor = new UidProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('uid', $record['extra']);
}
 
public function testGetUid()
{
$processor = new UidProcessor(10);
$this->assertEquals(10, strlen($processor->getUid()));
}
}
/vendor/monolog/monolog/tests/Monolog/Processor/WebProcessorTest.php
@@ -0,0 +1,113 @@
<?php
 
/*
* 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\Processor;
 
use Monolog\TestCase;
 
class WebProcessorTest extends TestCase
{
public function testProcessor()
{
$server = array(
'REQUEST_URI' => 'A',
'REMOTE_ADDR' => 'B',
'REQUEST_METHOD' => 'C',
'HTTP_REFERER' => 'D',
'SERVER_NAME' => 'F',
'UNIQUE_ID' => 'G',
);
 
$processor = new WebProcessor($server);
$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']);
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']);
$this->assertEquals($server['SERVER_NAME'], $record['extra']['server']);
$this->assertEquals($server['UNIQUE_ID'], $record['extra']['unique_id']);
}
 
public function testProcessorDoNothingIfNoRequestUri()
{
$server = array(
'REMOTE_ADDR' => 'B',
'REQUEST_METHOD' => 'C',
);
$processor = new WebProcessor($server);
$record = $processor($this->getRecord());
$this->assertEmpty($record['extra']);
}
 
public function testProcessorReturnNullIfNoHttpReferer()
{
$server = array(
'REQUEST_URI' => 'A',
'REMOTE_ADDR' => 'B',
'REQUEST_METHOD' => 'C',
'SERVER_NAME' => 'F',
);
$processor = new WebProcessor($server);
$record = $processor($this->getRecord());
$this->assertNull($record['extra']['referrer']);
}
 
public function testProcessorDoesNotAddUniqueIdIfNotPresent()
{
$server = array(
'REQUEST_URI' => 'A',
'REMOTE_ADDR' => 'B',
'REQUEST_METHOD' => 'C',
'SERVER_NAME' => 'F',
);
$processor = new WebProcessor($server);
$record = $processor($this->getRecord());
$this->assertFalse(isset($record['extra']['unique_id']));
}
 
public function testProcessorAddsOnlyRequestedExtraFields()
{
$server = array(
'REQUEST_URI' => 'A',
'REMOTE_ADDR' => 'B',
'REQUEST_METHOD' => 'C',
'SERVER_NAME' => 'F',
);
 
$processor = new WebProcessor($server, array('url', 'http_method'));
$record = $processor($this->getRecord());
 
$this->assertSame(array('url' => 'A', 'http_method' => 'C'), $record['extra']);
}
 
public function testProcessorConfiguringOfExtraFields()
{
$server = array(
'REQUEST_URI' => 'A',
'REMOTE_ADDR' => 'B',
'REQUEST_METHOD' => 'C',
'SERVER_NAME' => 'F',
);
 
$processor = new WebProcessor($server, array('url' => 'REMOTE_ADDR'));
$record = $processor($this->getRecord());
 
$this->assertSame(array('url' => 'B'), $record['extra']);
}
 
/**
* @expectedException UnexpectedValueException
*/
public function testInvalidData()
{
new WebProcessor(new \stdClass);
}
}