1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-08 06:06:40 +02:00

Merge pull request #422 from TheoKouzelis/issue/streamArgs

Invalid StreamHandler Arguments
This commit is contained in:
Jordi Boggiano
2014-09-29 22:51:43 +01:00
2 changed files with 29 additions and 6 deletions

View File

@@ -29,19 +29,23 @@ class StreamHandler extends AbstractProcessingHandler
protected $useLocking; protected $useLocking;
/** /**
* @param string $stream * @param resource|string $stream
* @param integer $level The minimum logging level at which this handler will be triggered * @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @param int|null $filePermission Optional file permissions (default (0644) are only for owner read/write) * @param int|null $filePermission Optional file permissions (default (0644) are only for owner read/write)
* @param Boolean $useLocking Try to lock log file before doing any writes * @param Boolean $useLocking Try to lock log file before doing any writes
*
* @throws InvalidArgumentException If stream is not a resource or string
*/ */
public function __construct($stream, $level = Logger::DEBUG, $bubble = true, $filePermission = null, $useLocking = false) public function __construct($stream, $level = Logger::DEBUG, $bubble = true, $filePermission = null, $useLocking = false)
{ {
parent::__construct($level, $bubble); parent::__construct($level, $bubble);
if (is_resource($stream)) { if (is_resource($stream)) {
$this->stream = $stream; $this->stream = $stream;
} else { } elseif (is_string($stream)) {
$this->url = $stream; $this->url = $stream;
} else {
throw new \InvalidArgumentException('A stream must either be a resource or a string.');
} }
$this->filePermission = $filePermission; $this->filePermission = $filePermission;

View File

@@ -75,6 +75,25 @@ class StreamHandlerTest extends TestCase
$handler->handle($this->getRecord()); $handler->handle($this->getRecord());
} }
public function invalidArgumentProvider()
{
return array(
array(1),
array(array()),
array(array('bogus://url')),
);
}
/**
* @dataProvider invalidArgumentProvider
* @expectedException InvalidArgumentException
* @covers Monolog\Handler\StreamHandler::__construct
*/
public function testWriteInvalidArgument($invalidArgument)
{
$handler = new StreamHandler($invalidArgument);
}
/** /**
* @expectedException UnexpectedValueException * @expectedException UnexpectedValueException
* @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::__construct