1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-04 20:27:31 +02:00

Fix issues highlighted by @stof on first code review

This commit is contained in:
Ando Roots
2014-08-28 22:58:52 +03:00
parent 7944eecbd8
commit c8d0830860
2 changed files with 22 additions and 22 deletions

View File

@@ -15,7 +15,9 @@ use Monolog\Formatter\LineFormatter;
use Monolog\Logger;
/**
* Sends logs to Fleep.io using WebHook integrations
* Sends logs to Fleep.io using Webhook integrations
*
* You'll need a Fleep.io account to use this handler.
*
* @see https://fleep.io/integrations/webhooks/ Fleep Webhooks Documentation
* @author Ando Roots <ando@sqroot.eu>
@@ -23,9 +25,6 @@ use Monolog\Logger;
class FleepHookHandler extends AbstractProcessingHandler
{
/**
* Fleep.io webhooks URI
*/
const HOOK_ENDPOINT = 'https://fleep.io/hook/';
/**
@@ -52,11 +51,10 @@ class FleepHookHandler extends AbstractProcessingHandler
/**
* Construct a new Fleep.io Handler.
*
* You'll need a Fleep.op account to use this handler.
* For instructions on how to create a new web hook in your conversations
* see https://fleep.io/integrations/webhooks/
*
* @param string $token Webhook token (ex: mTZG6s-XRfKdNTJtpVyVaA)
* @param string $token Webhook token
* @param bool|int $level The minimum logging level at which this handler will be triggered
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
* @throws \LogicException
@@ -73,14 +71,6 @@ class FleepHookHandler extends AbstractProcessingHandler
parent::__construct($level, $bubble);
}
/**
* @return string
*/
public function getToken()
{
return $this->token;
}
/**
* @return array
*/
@@ -94,10 +84,9 @@ class FleepHookHandler extends AbstractProcessingHandler
*
* Overloaded to remove empty context and extra arrays from the end of the log message.
*
* @author Ando Roots <ando@sqroot.eu>
* @return LineFormatter
*/
public function getDefaultFormatter()
protected function getDefaultFormatter()
{
return new LineFormatter(null, null, true, true);
@@ -106,7 +95,6 @@ class FleepHookHandler extends AbstractProcessingHandler
/**
* Handles a log record
*
* @author Ando Roots <ando@sqroot.eu>
* @param array $record
*/
protected function write(array $record)
@@ -118,7 +106,6 @@ class FleepHookHandler extends AbstractProcessingHandler
/**
* Prepares the record for sending to Fleep
*
* @author Ando Roots <ando@sqroot.eu>
* @param string $message The formatted log message to send
*/
protected function send($message)
@@ -137,7 +124,6 @@ class FleepHookHandler extends AbstractProcessingHandler
/**
* Sends a new Curl request
*
* @author Ando Roots <ando@sqroot.eu>
* @param array $options Curl parameters, including the endpoint URL and POST payload
*/
protected function execCurl(array $options)
@@ -154,7 +140,6 @@ class FleepHookHandler extends AbstractProcessingHandler
/**
* Adds or overwrites a curl option
*
* @author Ando Roots <ando@sqroot.eu>
* @param array $options An assoc array of Curl options, indexed by CURL_* constants
* @return $this
*/

View File

@@ -58,7 +58,22 @@ class FleepHookHandlerTest extends TestCase
*/
public function testConstructorSetsExpectedDefaults()
{
$this->assertEquals(self::TOKEN, $this->handler->getToken());
// Test that the $token is saved when calling the constructor
$token = self::TOKEN;
$handler = $this->mockHandler(array('execCurl'));
$handler->expects($this->once())
->method('execCurl')
->with(
$this->callback(
function ($curlOpts) use ($token) {
return substr($curlOpts[CURLOPT_URL], -strlen($token)) === $token;
}
)
);
$this->sendLog($handler);
// Test that default values are assigned to $level and $bubble
$this->assertEquals(Logger::DEBUG, $this->handler->getLevel());
$this->assertEquals(true, $this->handler->getBubble());
}
@@ -102,7 +117,7 @@ class FleepHookHandlerTest extends TestCase
$expectedFormatter = new LineFormatter(null, null, true, true);
$expected = $expectedFormatter->format($record);
$handlerFormatter = $this->handler->getDefaultFormatter();
$handlerFormatter = $this->handler->getFormatter();
$actual = $handlerFormatter->format($record);
$this->assertEquals($expected, $actual, 'Empty context and extra arrays should not be rendered');