summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Monolog/Handler/RotatingFileHandler.php13
-rw-r--r--tests/Monolog/Handler/RotatingFileHandlerTest.php18
2 files changed, 12 insertions, 19 deletions
diff --git a/src/Monolog/Handler/RotatingFileHandler.php b/src/Monolog/Handler/RotatingFileHandler.php
index cd93805..893a5cb 100644
--- a/src/Monolog/Handler/RotatingFileHandler.php
+++ b/src/Monolog/Handler/RotatingFileHandler.php
@@ -11,6 +11,7 @@
namespace Monolog\Handler;
+use InvalidArgumentException;
use Monolog\Logger;
/**
@@ -69,17 +70,15 @@ class RotatingFileHandler extends StreamHandler
public function setFilenameFormat($filenameFormat, $dateFormat)
{
if (!in_array($dateFormat, array(self::FILE_PER_DAY, self::FILE_PER_MONTH, self::FILE_PER_YEAR))) {
- trigger_error(
- 'Invalid date format - format should be one of '.
+ throw new InvalidArgumentException(
+ 'Invalid date format - format must be one of '.
'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '.
- 'or RotatingFileHandler::FILE_PER_YEAR.',
- E_USER_DEPRECATED
+ 'or RotatingFileHandler::FILE_PER_YEAR.'
);
}
if (substr_count($filenameFormat, '{date}') === 0) {
- trigger_error(
- 'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.',
- E_USER_DEPRECATED
+ throw new InvalidArgumentException(
+ 'Invalid filename format - format must contain at least `{date}`, because otherwise rotating is impossible.'
);
}
$this->filenameFormat = $filenameFormat;
diff --git a/tests/Monolog/Handler/RotatingFileHandlerTest.php b/tests/Monolog/Handler/RotatingFileHandlerTest.php
index 96e6dff..495d500 100644
--- a/tests/Monolog/Handler/RotatingFileHandlerTest.php
+++ b/tests/Monolog/Handler/RotatingFileHandlerTest.php
@@ -11,6 +11,7 @@
namespace Monolog\Handler;
+use InvalidArgumentException;
use Monolog\TestCase;
use PHPUnit_Framework_Error_Deprecated;
@@ -141,15 +142,10 @@ class RotatingFileHandlerTest extends TestCase
public function testAllowOnlyFixedDefinedDateFormats($dateFormat, $valid)
{
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
- $handler->setFilenameFormat('{filename}-{date}', $dateFormat);
if (!$valid) {
- $this->assertErrorWasTriggered(
- E_USER_DEPRECATED,
- 'Invalid date format - format should be one of '.
- 'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '.
- 'or RotatingFileHandler::FILE_PER_YEAR.'
- );
+ $this->setExpectedExceptionRegExp(InvalidArgumentException::class, '~^Invalid date format~');
}
+ $handler->setFilenameFormat('{filename}-{date}', $dateFormat);
}
public function dateFormatProvider()
@@ -169,13 +165,11 @@ class RotatingFileHandlerTest extends TestCase
public function testDisallowFilenameFormatsWithoutDate($filenameFormat, $valid)
{
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
- $handler->setFilenameFormat($filenameFormat, RotatingFileHandler::FILE_PER_DAY);
if (!$valid) {
- $this->assertErrorWasTriggered(
- E_USER_DEPRECATED,
- 'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.'
- );
+ $this->setExpectedExceptionRegExp(InvalidArgumentException::class, '~^Invalid filename format~');
}
+
+ $handler->setFilenameFormat($filenameFormat, RotatingFileHandler::FILE_PER_DAY);
}
public function filenameFormatProvider()