404

[ Avaa Bypassed ]




Upload:

Command:

botdev@18.190.219.249: ~ $
<?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\Handler;

use Monolog\Formatter\LineFormatter;
use Monolog\TestCase;
use Monolog\Logger;

class NewRelicHandlerTest extends TestCase
{
    public static $appname;
    public static $customParameters;
    public static $transactionName;

    public function setUp()
    {
        self::$appname = null;
        self::$customParameters = array();
        self::$transactionName = null;
    }

    /**
     * @expectedException Monolog\Handler\MissingExtensionException
     */
    public function testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded()
    {
        $handler = new StubNewRelicHandlerWithoutExtension();
        $handler->handle($this->getRecord(Logger::ERROR));
    }

    public function testThehandlerCanHandleTheRecord()
    {
        $handler = new StubNewRelicHandler();
        $handler->handle($this->getRecord(Logger::ERROR));
    }

    public function testThehandlerCanAddContextParamsToTheNewRelicTrace()
    {
        $handler = new StubNewRelicHandler();
        $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('a' => 'b')));
        $this->assertEquals(array('context_a' => 'b'), self::$customParameters);
    }

    public function testThehandlerCanAddExplodedContextParamsToTheNewRelicTrace()
    {
        $handler = new StubNewRelicHandler(Logger::ERROR, true, self::$appname, true);
        $handler->handle($this->getRecord(
            Logger::ERROR,
            'log message',
            array('a' => array('key1' => 'value1', 'key2' => 'value2'))
        ));
        $this->assertEquals(
            array('context_a_key1' => 'value1', 'context_a_key2' => 'value2'),
            self::$customParameters
        );
    }

    public function testThehandlerCanAddExtraParamsToTheNewRelicTrace()
    {
        $record = $this->getRecord(Logger::ERROR, 'log message');
        $record['extra'] = array('c' => 'd');

        $handler = new StubNewRelicHandler();
        $handler->handle($record);

        $this->assertEquals(array('extra_c' => 'd'), self::$customParameters);
    }

    public function testThehandlerCanAddExplodedExtraParamsToTheNewRelicTrace()
    {
        $record = $this->getRecord(Logger::ERROR, 'log message');
        $record['extra'] = array('c' => array('key1' => 'value1', 'key2' => 'value2'));

        $handler = new StubNewRelicHandler(Logger::ERROR, true, self::$appname, true);
        $handler->handle($record);

        $this->assertEquals(
            array('extra_c_key1' => 'value1', 'extra_c_key2' => 'value2'),
            self::$customParameters
        );
    }

    public function testThehandlerCanAddExtraContextAndParamsToTheNewRelicTrace()
    {
        $record = $this->getRecord(Logger::ERROR, 'log message', array('a' => 'b'));
        $record['extra'] = array('c' => 'd');

        $handler = new StubNewRelicHandler();
        $handler->handle($record);

        $expected = array(
            'context_a' => 'b',
            'extra_c' => 'd',
        );

        $this->assertEquals($expected, self::$customParameters);
    }

    public function testThehandlerCanHandleTheRecordsFormattedUsingTheLineFormatter()
    {
        $handler = new StubNewRelicHandler();
        $handler->setFormatter(new LineFormatter());
        $handler->handle($this->getRecord(Logger::ERROR));
    }

    public function testTheAppNameIsNullByDefault()
    {
        $handler = new StubNewRelicHandler();
        $handler->handle($this->getRecord(Logger::ERROR, 'log message'));

        $this->assertEquals(null, self::$appname);
    }

    public function testTheAppNameCanBeInjectedFromtheConstructor()
    {
        $handler = new StubNewRelicHandler(Logger::DEBUG, false, 'myAppName');
        $handler->handle($this->getRecord(Logger::ERROR, 'log message'));

        $this->assertEquals('myAppName', self::$appname);
    }

    public function testTheAppNameCanBeOverriddenFromEachLog()
    {
        $handler = new StubNewRelicHandler(Logger::DEBUG, false, 'myAppName');
        $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('appname' => 'logAppName')));

        $this->assertEquals('logAppName', self::$appname);
    }

    public function testTheTransactionNameIsNullByDefault()
    {
        $handler = new StubNewRelicHandler();
        $handler->handle($this->getRecord(Logger::ERROR, 'log message'));

        $this->assertEquals(null, self::$transactionName);
    }

    public function testTheTransactionNameCanBeInjectedFromTheConstructor()
    {
        $handler = new StubNewRelicHandler(Logger::DEBUG, false, null, false, 'myTransaction');
        $handler->handle($this->getRecord(Logger::ERROR, 'log message'));

        $this->assertEquals('myTransaction', self::$transactionName);
    }

    public function testTheTransactionNameCanBeOverriddenFromEachLog()
    {
        $handler = new StubNewRelicHandler(Logger::DEBUG, false, null, false, 'myTransaction');
        $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('transaction_name' => 'logTransactName')));

        $this->assertEquals('logTransactName', self::$transactionName);
    }
}

class StubNewRelicHandlerWithoutExtension extends NewRelicHandler
{
    protected function isNewRelicEnabled()
    {
        return false;
    }
}

class StubNewRelicHandler extends NewRelicHandler
{
    protected function isNewRelicEnabled()
    {
        return true;
    }
}

function newrelic_notice_error()
{
    return true;
}

function newrelic_set_appname($appname)
{
    return NewRelicHandlerTest::$appname = $appname;
}

function newrelic_name_transaction($transactionName)
{
    return NewRelicHandlerTest::$transactionName = $transactionName;
}

function newrelic_add_custom_parameter($key, $value)
{
    NewRelicHandlerTest::$customParameters[$key] = $value;

    return true;
}

Filemanager

Name Type Size Permission Actions
Fixtures Folder 0755
Slack Folder 0755
AbstractHandlerTest.php File 3.99 KB 0644
AbstractProcessingHandlerTest.php File 2.59 KB 0644
AmqpHandlerTest.php File 4.09 KB 0644
BrowserConsoleHandlerTest.php File 4.11 KB 0644
BufferHandlerTest.php File 5.23 KB 0644
ChromePHPHandlerTest.php File 4.78 KB 0644
CouchDBHandlerTest.php File 751 B 0644
DeduplicationHandlerTest.php File 5.99 KB 0644
DoctrineCouchDBHandlerTest.php File 1.44 KB 0644
DynamoDbHandlerTest.php File 2.46 KB 0644
ElasticSearchHandlerTest.php File 7.51 KB 0644
ErrorLogHandlerTest.php File 2.1 KB 0644
FilterHandlerTest.php File 6.26 KB 0644
FingersCrossedHandlerTest.php File 10.84 KB 0644
FirePHPHandlerTest.php File 2.9 KB 0644
FleepHookHandlerTest.php File 2.19 KB 0644
FlowdockHandlerTest.php File 2.53 KB 0644
GelfHandlerLegacyTest.php File 3.12 KB 0644
GelfHandlerTest.php File 3.31 KB 0644
GelfMockMessagePublisher.php File 500 B 0644
GroupHandlerTest.php File 3.7 KB 0644
HandlerWrapperTest.php File 3.22 KB 0644
HipChatHandlerTest.php File 10.23 KB 0644
InsightOpsHandlerTest.php File 2.33 KB 0644
LogEntriesHandlerTest.php File 2.34 KB 0644
MailHandlerTest.php File 2.15 KB 0644
MockRavenClient.php File 573 B 0644
MongoDBHandlerTest.php File 1.71 KB 0644
NativeMailerHandlerTest.php File 3.65 KB 0644
NewRelicHandlerTest.php File 5.92 KB 0644
NullHandlerTest.php File 747 B 0644
PHPConsoleHandlerTest.php File 9.66 KB 0644
PsrHandlerTest.php File 1.25 KB 0644
PushoverHandlerTest.php File 5.13 KB 0644
RavenHandlerTest.php File 8.69 KB 0644
RedisHandlerTest.php File 3.83 KB 0644
RollbarHandlerTest.php File 2.14 KB 0644
RotatingFileHandlerTest.php File 8.95 KB 0644
SamplingHandlerTest.php File 845 B 0644
SlackHandlerTest.php File 5.31 KB 0644
SlackWebhookHandlerTest.php File 3.13 KB 0644
SlackbotHandlerTest.php File 1.13 KB 0644
SocketHandlerTest.php File 9.33 KB 0644
StreamHandlerTest.php File 5.8 KB 0644
SwiftMailerHandlerTest.php File 3.74 KB 0644
SyslogHandlerTest.php File 1.25 KB 0644
SyslogUdpHandlerTest.php File 2.26 KB 0644
TestHandlerTest.php File 3.95 KB 0644
UdpSocketTest.php File 1.63 KB 0644
WhatFailureGroupHandlerTest.php File 4.73 KB 0644
ZendMonitorHandlerTest.php File 1.99 KB 0644