Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'feature/log-factory' into develop

Close #2725
  • Loading branch information...
commit 793f92adac58c28d197d16f66e37775d8e996714 2 parents bbc9798 + 4ec7bb1
@weierophinney weierophinney authored
View
10 library/Zend/Log/Formatter/Base.php
@@ -32,10 +32,18 @@ class Base implements FormatterInterface
* Class constructor
*
* @see http://php.net/manual/en/function.date.php
- * @param null|string $dateTimeFormat Format for DateTime objects
+ * @param null|string|array|Traversable $dateTimeFormat Format for DateTime objects
*/
public function __construct($dateTimeFormat = null)
{
+ if ($dateTimeFormat instanceof Traversable) {
+ $dateTimeFormat = iterator_to_array($dateTimeFormat);
+ }
+
+ if (is_array($dateTimeFormat)) {
+ $dateTimeFormat = isset($dateTimeFormat['dateTimeFormat'])? $dateTimeFormat['dateTimeFormat'] : null;
+ }
+
if (null !== $dateTimeFormat) {
$this->dateTimeFormat = $dateTimeFormat;
}
View
9 library/Zend/Log/Formatter/Db.php
@@ -11,6 +11,7 @@
namespace Zend\Log\Formatter;
use DateTime;
+use Traversable;
/**
* @category Zend
@@ -35,6 +36,14 @@ class Db implements FormatterInterface
*/
public function __construct($dateTimeFormat = null)
{
+ if ($dateTimeFormat instanceof Traversable) {
+ $dateTimeFormat = iterator_to_array($dateTimeFormat);
+ }
+
+ if (is_array($dateTimeFormat)) {
+ $dateTimeFormat = isset($dateTimeFormat['dateTimeFormat'])? $dateTimeFormat['dateTimeFormat'] : null;
+ }
+
if (null !== $dateTimeFormat) {
$this->setDateTimeFormat($dateTimeFormat);
}
View
10 library/Zend/Log/Formatter/Simple.php
@@ -10,6 +10,7 @@
namespace Zend\Log\Formatter;
+use Traversable;
use DateTime;
use Zend\Log\Exception;
@@ -39,6 +40,15 @@ class Simple extends Base
*/
public function __construct($format = null, $dateTimeFormat = null)
{
+ if ($format instanceof Traversable) {
+ $format = iterator_to_array($format);
+ }
+
+ if (is_array($format)) {
+ $dateTimeFormat = isset($format['dateTimeFormat'])? $format['dateTimeFormat'] : null;
+ $format = isset($format['format'])? $format['format'] : null;
+ }
+
if (isset($format) && !is_string($format)) {
throw new Exception\InvalidArgumentException('Format must be a string');
}
View
40 library/Zend/Log/Logger.php
@@ -83,12 +83,48 @@ class Logger implements LoggerInterface
/**
* Constructor
*
- * @todo support configuration (writers, dateTimeFormat, and writer plugin manager)
+ * Set options for an logger. Accepted options are:
+ * - writers: array of writers to add to this logger
+ * - exceptionhandler: if true register this logger as exceptionhandler
+ * - errorhandler: if true register this logger as errorhandler
+ *
+ * @param array|\Traversable $options
* @return Logger
+ * @throws Exception\InvalidArgumentException
*/
- public function __construct()
+ public function __construct(array $options = null)
{
$this->writers = new SplPriorityQueue();
+
+ if ($options instanceof Traversable) {
+ $options = ArrayUtils::iteratorToArray($options);
+ }
+
+ if (is_array($options)) {
+
+ if(isset($options['writers']) && is_array($options['writers'])) {
+ foreach($options['writers'] as $writer) {
+
+ if(!isset($writer['name'])) {
+ throw new Exception\InvalidArgumentException('Options must contain a name for the writer');
+ }
+
+ $priority = (isset($writer['priority'])) ? $writer['priority'] : null;
+ $writerOptions = (isset($writer['options'])) ? $writer['options'] : null;
+
+ $this->addWriter($writer['name'], $priority, $writerOptions);
+ }
+ }
+
+ if(isset($options['exceptionhandler']) && $options['exceptionhandler'] === true) {
+ self::registerExceptionHandler($this);
+ }
+
+ if(isset($options['errorhandler']) && $options['errorhandler'] === true) {
+ self::registerErrorHandler($this);
+ }
+
+ }
}
/**
View
31 library/Zend/Log/LoggerServiceFactory.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Log
+ */
+
+namespace Zend\Log;
+
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+
+/**
+ * Logger.
+ *
+ * @category Zend
+ * @package Zend_Log
+ */
+class LoggerServiceFactory implements FactoryInterface
+{
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ // Configure the logger
+ $config = $serviceLocator->get('Config');
+ $logConfig = isset($config['log']) ? $config['log'] : array();
+ $logger = new Logger($logConfig);
+ }
+}
View
124 library/Zend/Log/Writer/AbstractWriter.php
@@ -10,9 +10,10 @@
namespace Zend\Log\Writer;
+use Traversable;
use Zend\Log\Exception;
use Zend\Log\Filter;
-use Zend\Log\Formatter\FormatterInterface as Formatter;
+use Zend\Log\Formatter;
use Zend\Stdlib\ErrorHandler;
/**
@@ -30,6 +31,13 @@
protected $filterPlugins;
/**
+ * Formatter plugins
+ *
+ * @var FormatterPluginManager
+ */
+ protected $formatterPlugins;
+
+ /**
* Filter chain
*
* @var Filter\FilterInterface[]
@@ -58,6 +66,50 @@
protected $errorsToExceptionsConversionLevel = E_WARNING;
/**
+ * Constructor
+ *
+ * Set options for an writer. Accepted options are:
+ * - filters: array of filters to add to this filter
+ * - formatter: formatter for this writer
+ *
+ * @param array|\Traversable $options
+ * @return Logger
+ * @throws Exception\InvalidArgumentException
+ */
+ public function __construct($options = null)
+ {
+ if ($options instanceof Traversable) {
+ $options = iterator_to_array($options);
+ }
+
+ if (is_array($options)) {
+
+ if(isset($options['filters']) && is_array($options['filters'])) {
+ foreach($options['filters'] as $filter) {
+ if(!isset($filter['name'])) {
+ throw new Exception\InvalidArgumentException('Options must contain a name for the filter');
+ }
+ $filterOptions = (isset($filter['options'])) ? $filter['options'] : null;
+ $this->addFilter($filter['name'], $filterOptions);
+ }
+ }
+
+ if(isset($options['formatter'])) {
+ $formatter = $options['formatter'];
+ if(is_string($formatter) || $formatter instanceof Formatter\FormatterInterface) {
+ $this->setFormatter($formatter);
+ } elseif(is_array($formatter)) {
+ if(!isset($formatter['name'])) {
+ throw new Exception\InvalidArgumentException('Options must contain a name for the formatter');
+ }
+ $formatterOptions = (isset($formatter['options'])) ? $formatter['options'] : null;
+ $this->setFormatter($formatter['name'], $formatterOptions);
+ }
+ }
+ }
+ }
+
+ /**
* Add a filter specific to this writer.
*
* @param int|string|Filter\FilterInterface $filter
@@ -77,7 +129,8 @@ public function addFilter($filter, array $options = null)
if (!$filter instanceof Filter\FilterInterface) {
throw new Exception\InvalidArgumentException(sprintf(
- 'Writer must implement Zend\Log\Filter\FilterInterface; received "%s"',
+ 'Writer must implement %s\Filter\FilterInterface; received "%s"',
+ __NAMESPACE__,
is_object($filter) ? get_class($filter) : gettype($filter)
));
}
@@ -136,6 +189,56 @@ public function filterPlugin($name, array $options = null)
}
/**
+ * Get formatter plugin manager
+ *
+ * @return FormatterPluginManager
+ */
+ public function getFormatterPluginManager()
+ {
+ if (null === $this->formatterPlugins) {
+ $this->setFormatterPluginManager(new FormatterPluginManager());
+ }
+ return $this->formatterPlugins;
+ }
+
+ /**
+ * Set formatter plugin manager
+ *
+ * @param string|FormatterPluginManager $plugins
+ * @return self
+ * @throws Exception\InvalidArgumentException
+ */
+ public function setFormatterPluginManager($plugins)
+ {
+ if (is_string($plugins)) {
+ $plugins = new $plugins;
+ }
+ if (!$plugins instanceof FormatterPluginManager) {
+ throw new Exception\InvalidArgumentException(sprintf(
+ 'Writer plugin manager must extend %s\FormatterPluginManager; received %s',
+ __NAMESPACE__,
+ is_object($plugins) ? get_class($plugins) : gettype($plugins)
+ ));
+ }
+
+ $this->formatterPlugins = $plugins;
+ return $this;
+ }
+
+
+ /**
+ * Get formatter instance
+ *
+ * @param string $name
+ * @param array|null $options
+ * @return Formatter\FormatterInterface
+ */
+ public function formatterPlugin($name, array $options = null)
+ {
+ return $this->getFormatterPluginManager()->get($name, $options);
+ }
+
+ /**
* Log a message to this writer.
*
* @param array $event log data event
@@ -178,11 +281,24 @@ public function write(array $event)
/**
* Set a new formatter for this writer
*
- * @param Formatter $formatter
+ * @param string|Formatter\FormatterInterface $formatter
* @return self
+ * @throws Exception\InvalidArgumentException
*/
- public function setFormatter(Formatter $formatter)
+ public function setFormatter($formatter, array $options = null)
{
+ if (is_string($formatter)) {
+ $formatter = $this->formatterPlugin($formatter, $options);
+ }
+
+ if (!$formatter instanceof Formatter\FormatterInterface) {
+ throw new Exception\InvalidArgumentException(sprintf(
+ 'Formatter must implement %s\Formatter\FormatterInterface; received "%s"',
+ __NAMESPACE__,
+ is_object($formatter) ? get_class($formatter) : gettype($formatter)
+ ));
+ }
+
$this->formatter = $formatter;
return $this;
}
View
2  library/Zend/Log/Writer/FilterPluginManager.php
@@ -44,7 +44,7 @@ class FilterPluginManager extends AbstractPluginManager
/**
* Validate the plugin
*
- * Checks that the writer loaded is an instance of Filter\FilterInterface.
+ * Checks that the filter loaded is an instance of Filter\FilterInterface.
*
* @param mixed $plugin
* @return void
View
108 library/Zend/Log/Writer/FingersCrossed.php
@@ -9,6 +9,8 @@
*/
namespace Zend\Log\Writer;
+use Traversable;
+use Zend\Stdlib\ArrayUtils;
use Zend\Log\Filter\Priority as PriorityFilter;
use Zend\Log\Filter\FilterInterface;
use Zend\Log\Formatter\FormatterInterface;
@@ -16,6 +18,7 @@
use Zend\Log\Logger;
use Zend\Log\Writer\WriterInterface;
use Zend\Log\Writer\AbstractWriter;
+use Zend\Log\WriterPluginManager;
/**
* Buffers all events until the strategy determines to flush them.
@@ -36,6 +39,13 @@ class FingersCrossed extends AbstractWriter
protected $writer;
/**
+ * Writer plugins
+ *
+ * @var WriterPluginManager
+ */
+ protected $writerPlugins;
+
+ /**
* Flag if buffering is enabled
*
* @var boolean
@@ -60,25 +70,114 @@ class FingersCrossed extends AbstractWriter
/**
* Constructor
*
- * @param WriterInterface $writer Wrapped writer
+ * @param WriterInterface|string|array|Traversable $writer Wrapped writer or array of configuration options
* @param FilterInterface|int $filterOrPriority Filter or log priority which determines buffering of events
* @param int $bufferSize Maximum buffer size
*/
- public function __construct(WriterInterface $writer, $filterOrPriority = null, $bufferSize = 0)
+ public function __construct($writer, $filterOrPriority = null, $bufferSize = 0)
{
$this->writer = $writer;
+ if ($writer instanceof Traversable) {
+ $writer = ArrayUtils::iteratorToArray($writer);
+ }
+
+ if (is_array($writer)) {
+ $filterOrPriority = isset($writer['priority']) ? $writer['priority'] : null;
+ $bufferSize = isset($writer['bufferSize']) ? $writer['bufferSize'] : null;
+ $writer = isset($writer['writer']) ? $writer['writer'] : null;
+ }
+
if (null === $filterOrPriority) {
$filterOrPriority = new PriorityFilter(Logger::WARN);
} elseif (!$filterOrPriority instanceof FilterInterface) {
$filterOrPriority = new PriorityFilter($filterOrPriority);
}
+ if (is_array($writer) && isset($writer['name'])) {
+ $this->setWriter($writer['name'], $writer['options']);
+ } else {
+ $this->setWriter($writer);
+ }
$this->addFilter($filterOrPriority);
$this->bufferSize = $bufferSize;
}
/**
+ * Set a new formatter for this writer
+ *
+ * @param string|Formatter\FormatterInterface $formatter
+ * @return self
+ * @throws Exception\InvalidArgumentException
+ */
+ public function setWriter($writer, array $options = null)
+ {
+ if (is_string($writer)) {
+ $writer = $this->writerPlugin($writer, $options);
+ }
+
+ if (!$writer instanceof WriterInterface) {
+ throw new Exception\InvalidArgumentException(sprintf(
+ 'Formatter must implement %s\Formatter\FormatterInterface; received "%s"',
+ __NAMESPACE__,
+ is_object($writer) ? get_class($writer) : gettype($writer)
+ ));
+ }
+
+ $this->writer = $writer;
+ return $this;
+ }
+
+ /**
+ * Get writer plugin manager
+ *
+ * @return WriterPluginManager
+ */
+ public function getWriterPluginManager()
+ {
+ if (null === $this->writerPlugins) {
+ $this->setWriterPluginManager(new WriterPluginManager());
+ }
+ return $this->writerPlugins;
+ }
+
+ /**
+ * Set writer plugin manager
+ *
+ * @param string|WriterPluginManager $plugins
+ * @return Logger
+ * @throws Exception\InvalidArgumentException
+ */
+ public function setWriterPluginManager($plugins)
+ {
+ if (is_string($plugins)) {
+ $plugins = new $plugins;
+ }
+ if (!$plugins instanceof WriterPluginManager) {
+ throw new Exception\InvalidArgumentException(sprintf(
+ 'Writer plugin manager must extend %s\WriterPluginManager; received %s',
+ __NAMESPACE__,
+ is_object($plugins) ? get_class($plugins) : gettype($plugins)
+ ));
+ }
+
+ $this->writerPlugins = $plugins;
+ return $this;
+ }
+
+ /**
+ * Get writer instance
+ *
+ * @param string $name
+ * @param array|null $options
+ * @return Writer\WriterInterface
+ */
+ public function writerPlugin($name, array $options = null)
+ {
+ return $this->getWriterPluginManager()->get($name, $options);
+ }
+
+ /**
* Log a message to this writer.
*
* @param array $event log data event
@@ -148,9 +247,10 @@ public function reset()
* Stub in accordance to parent method signature.
* Fomatters must be set on the wrapped writer.
*
- * @param Formatter $formatter
+ * @param string|Formatter\FormatterInterface $formatter
+ * @return WriterInterface
*/
- public function setFormatter(FormatterInterface $formatter)
+ public function setFormatter($formatter)
{
return $this->writer;
}
View
66 library/Zend/Log/Writer/FormatterPluginManager.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Log
+ */
+
+namespace Zend\Log\Writer;
+
+use Zend\ServiceManager\AbstractPluginManager;
+use Zend\Log\Formatter;
+use Zend\Log\Exception;
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ */
+class FormatterPluginManager extends AbstractPluginManager
+{
+ /**
+ * Default set of formatters
+ *
+ * @var array
+ */
+ protected $invokableClasses = array(
+ 'base' => 'Zend\Log\Formatter\Base',
+ 'simple' => 'Zend\Log\Formatter\Simple',
+ 'xml' => 'Zend\Log\Formatter\Xml',
+ 'db' => 'Zend\Log\Formatter\Db',
+ 'errorhandler' => 'Zend\Log\Formatter\ErrorHandler',
+ 'exceptionhandler' => 'Zend\Log\Formatter\ExceptionHandler',
+ );
+
+ /**
+ * Allow many filters of the same type
+ *
+ * @var bool
+ */
+ protected $shareByDefault = false;
+
+ /**
+ * Validate the plugin
+ *
+ * Checks that the formatter loaded is an instance of Formatter\FormatterInterface.
+ *
+ * @param mixed $plugin
+ * @return void
+ * @throws Exception\InvalidArgumentException if invalid
+ */
+ public function validatePlugin($plugin)
+ {
+ if ($plugin instanceof Formatter\FormatterInterface) {
+ // we're okay
+ return;
+ }
+
+ throw new Exception\InvalidArgumentException(sprintf(
+ 'Plugin of type %s is invalid; must implement %s\Formatter\FormatterInterface',
+ (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
+ __NAMESPACE__
+ ));
+ }
+}
View
9 library/Zend/Log/Writer/MongoDB.php
@@ -89,13 +89,12 @@ public function __construct($mongo, $database, $collection, array $saveOptions =
/**
* This writer does not support formatting.
*
- * @param Zend\Log\Formatter\FormatterInterface $formatter
- * @return void
- * @throws Zend\Log\Exception\InvalidArgumentException
+ * @param string|Zend\Log\Formatter\FormatterInterface $formatter
+ * @return WriterInterface
*/
- public function setFormatter(FormatterInterface $formatter)
+ public function setFormatter($formatter)
{
- throw new InvalidArgumentException(get_class() . ' does not support formatting');
+ return $this;
}
/**
View
6 library/Zend/Log/Writer/WriterInterface.php
@@ -22,7 +22,7 @@
/**
* Add a log filter to the writer
*
- * @param int|Filter $filter
+ * @param int|string|Filter $filter
* @return WriterInterface
*/
public function addFilter($filter);
@@ -30,10 +30,10 @@ public function addFilter($filter);
/**
* Set a message formatter for the writer
*
- * @param Formatter $formatter
+ * @param string|Formatter $formatter
* @return WriterInterface
*/
- public function setFormatter(Formatter $formatter);
+ public function setFormatter($formatter);
/**
* Write a log message
View
11 tests/ZendTest/Log/Formatter/BaseTest.php
@@ -64,6 +64,17 @@ public function testSetDateTimeFormat($dateTimeFormat)
$this->assertEquals($dateTimeFormat, $formatter->getDateTimeFormat());
}
+ /**
+ * @dataProvider provideDateTimeFormats
+ */
+ public function testSetDateTimeFormatInConstructor($dateTimeFormat)
+ {
+ $options = array('dateTimeFormat' => $dateTimeFormat);
+ $formatter = new BaseFormatter($options);
+
+ $this->assertEquals($dateTimeFormat, $formatter->getDateTimeFormat());
+ }
+
public function testFormatAllTypes()
{
$datetime = new DateTime();
View
12 tests/ZendTest/Log/Formatter/SimpleTest.php
@@ -28,6 +28,18 @@ public function testConstructorThrowsOnBadFormatString()
new Simple(1);
}
+ /**
+ * @dataProvider provideDateTimeFormats
+ */
+ public function testConstructorWithOptions($dateTimeFormat)
+ {
+ $options = array('dateTimeFormat' => $dateTimeFormat, 'format' => '%timestamp%');
+ $formatter = new Simple($options);
+
+ $this->assertEquals($dateTimeFormat, $formatter->getDateTimeFormat());
+ $this->assertAttributeEquals('%timestamp%', 'format', $formatter);
+ }
+
public function testDefaultFormat()
{
$date = new DateTime('2012-08-28T18:15:00Z');
View
33 tests/ZendTest/Log/LoggerTest.php
@@ -259,4 +259,37 @@ public function testRegisterErrorHandler()
Logger::unregisterErrorHandler();
$this->assertEquals($writer->events[0]['message'], 'Undefined variable: test');
}
+
+ public function testOptionsWithMock()
+ {
+ $options = array('writers' => array(
+ 'first_writer' => array(
+ 'name' => 'mock',
+ )
+ ));
+ $logger = new Logger($options);
+
+ $writers = $logger->getWriters()->toArray();
+ $this->assertCount(1, $writers);
+ $this->assertInstanceOf('Zend\Log\Writer\Mock', $writers[0]);
+ }
+
+ public function testOptionsWithWriterOptions()
+ {
+ $options = array('writers' => array(
+ array(
+ 'name' => 'stream',
+ 'options' => array(
+ 'stream' => 'php://output',
+ 'log_separator' => 'foo'
+ ),
+ )
+ ));
+ $logger = new Logger($options);
+
+ $writers = $logger->getWriters()->toArray();
+ $this->assertCount(1, $writers);
+ $this->assertInstanceOf('Zend\Log\Writer\Stream', $writers[0]);
+ $this->assertEquals('foo', $writers[0]->getLogSeparator());
+ }
}
View
37 tests/ZendTest/Log/Writer/AbstractTest.php
@@ -36,10 +36,16 @@ protected function setUp()
public function testSetFormatter()
{
$this->_writer->setFormatter(new SimpleFormatter());
- $this->setExpectedException('PHPUnit_Framework_Error');
+ $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException');
$this->_writer->setFormatter(new \StdClass());
}
+ public function testSetSimpleFormatterByName()
+ {
+ $instance = $this->_writer->setFormatter('simple');
+ $this->assertAttributeInstanceOf('Zend\Log\Formatter\Simple', 'formatter', $instance);
+ }
+
public function testAddFilter()
{
$this->_writer->addFilter(1);
@@ -81,4 +87,33 @@ public function testConvertErrorsToException()
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
$writer->write(array('message' => 'test'));
}
+
+ public function testConstructorWithOptions()
+ {
+ $options = array('filters' => array(
+ array(
+ 'name' => 'mock',
+ ),
+ array(
+ 'name' => 'priority',
+ 'options' => array(
+ 'priority' => 3,
+ ),
+ ),
+ ),
+ 'formatter' => array(
+ 'name' => 'base',
+ ),
+ );
+
+ $writer = new ConcreteWriter($options);
+
+ $this->assertAttributeInstanceOf('Zend\Log\Formatter\Base', 'formatter', $writer);
+
+ $filters = $this->readAttribute($writer, 'filters');
+ $this->assertCount(2, $filters);
+
+ $this->assertInstanceOf('Zend\Log\Filter\Priority', $filters[1]);
+ $this->assertEquals(3, $this->readAttribute($filters[1], 'priority'));
+ }
}
View
2  tests/ZendTest/Log/Writer/DbTest.php
@@ -202,7 +202,7 @@ public function testShutdownRemovesReferenceToDatabaseInstance()
*/
public function testThrowStrictSetFormatter()
{
- $this->setExpectedException('PHPUnit_Framework_Error');
+ $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException');
$this->writer->setFormatter(new \StdClass());
}
View
27 tests/ZendTest/Log/Writer/FingersCrossedTest.php
@@ -54,4 +54,31 @@ public function testAfterFlushing()
$this->assertSame(count($wrappedWriter->events), 3);
}
+
+ public function setWriterByName()
+ {
+ $writer = new FingersCrossedWriter('mock');
+ $this->assertAttributeInstanceOf('Zend\Log\Writer\Mock', 'writer', $writer);
+ }
+
+ public function testConstructorOptions()
+ {
+ $options = array('writer' => 'mock', 'priority' => 3);
+ $writer = new FingersCrossedWriter($options);
+ $this->assertAttributeInstanceOf('Zend\Log\Writer\Mock', 'writer', $writer);
+
+ $filters = $this->readAttribute($writer, 'filters');
+ $this->assertCount(1, $filters);
+ $this->assertInstanceOf('Zend\Log\Filter\Priority', $filters[0]);
+ $this->assertAttributeEquals(3, 'priority', $filters[0]);
+ }
+
+ public function testFormattingIsNotSupported()
+ {
+ $options = array('writer' => 'mock', 'priority' => 3);
+ $writer = new FingersCrossedWriter($options);
+
+ $writer->setFormatter($this->getMock('Zend\Log\Formatter\FormatterInterface'));
+ $this->assertAttributeEmpty('formatter', $writer);
+ }
}
View
4 tests/ZendTest/Log/Writer/MongoDBTest.php
@@ -48,14 +48,12 @@ public function setUp()
->will($this->returnValue($this->mongoCollection));
}
- /**
- * @expectedException Zend\Log\Exception\InvalidArgumentException
- */
public function testFormattingIsNotSupported()
{
$writer = new MongoDBWriter($this->mongo, $this->database, $this->collection);
$writer->setFormatter($this->getMock('Zend\Log\Formatter\FormatterInterface'));
+ $this->assertAttributeEmpty('formatter', $writer);
}
public function testWriteWithDefaultSaveOptions()
Please sign in to comment.
Something went wrong with that request. Please try again.