From ae86b73241a88913d4231d4dd0e89bf9e236b655 Mon Sep 17 00:00:00 2001 From: sasa Date: Tue, 5 Oct 2010 01:09:03 +0200 Subject: [PATCH 1/2] refactored Zend\Log for exceptions milestone --- src/Exception.php | 5 +-- src/Exception/InvalidArgumentException.php | 7 ++++ src/Exception/NotImplementedException.php | 7 ++++ src/Exception/RuntimeException.php | 7 ++++ src/Filter/AbstractFilter.php | 6 +-- src/Filter/Message.php | 7 ++-- src/Filter/Priority.php | 10 ++--- src/Filter/SuppressFilter.php | 1 - src/Formatter/Simple.php | 6 +-- src/Logger.php | 45 ++++++++++++++-------- src/Writer.php | 1 - src/Writer/AbstractWriter.php | 9 +++-- src/Writer/Db.php | 11 ++++-- src/Writer/Firebug.php | 1 - src/Writer/Mail.php | 15 +++++--- src/Writer/Mock.php | 1 - src/Writer/Null.php | 1 - src/Writer/Stream.php | 14 ++++--- src/Writer/Syslog.php | 10 +++-- src/Writer/ZendMonitor.php | 2 - test/Filter/MessageTest.php | 2 +- test/Filter/PriorityTest.php | 4 +- test/Formatter/SimpleTest.php | 2 +- test/LoggerTest.php | 16 ++++---- test/Writer/AbstractTest.php | 2 +- test/Writer/DbTest.php | 4 +- test/Writer/MailTest.php | 4 +- test/Writer/StreamTest.php | 10 ++--- test/Writer/SyslogTest.php | 4 +- 29 files changed, 124 insertions(+), 90 deletions(-) create mode 100644 src/Exception/InvalidArgumentException.php create mode 100644 src/Exception/NotImplementedException.php create mode 100644 src/Exception/RuntimeException.php diff --git a/src/Exception.php b/src/Exception.php index 4db8f943..f51c05ec 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -25,12 +25,11 @@ namespace Zend\Log; /** - * @uses \Zend\Exception * @category Zend * @package Zend_Log * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id$ */ -class Exception extends \Zend\Exception -{} +interface Exception +{} \ No newline at end of file diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php new file mode 100644 index 00000000..c057b247 --- /dev/null +++ b/src/Exception/InvalidArgumentException.php @@ -0,0 +1,7 @@ +_regexp = $regexp; } @@ -61,7 +61,6 @@ public function __construct($regexp) * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Filter\Message - * @throws \Zend\Log\Exception */ static public function factory($config = array()) { diff --git a/src/Filter/Priority.php b/src/Filter/Priority.php index 256114f2..a8c322eb 100644 --- a/src/Filter/Priority.php +++ b/src/Filter/Priority.php @@ -26,7 +26,7 @@ namespace Zend\Log\Filter; /** - * @uses \Zend\Log\Exception + * @uses \Zend\Log\Exception\InvalidArgumentException * @uses \Zend\Log\Filter\AbstractFilter * @category Zend * @package Zend_Log @@ -53,12 +53,12 @@ class Priority extends AbstractFilter * * @param integer $priority Priority * @param string $operator Comparison operator - * @throws \Zend\Log\Exception + * @throws \Zend\Log\Exception\InvalidArgumentException */ public function __construct($priority, $operator = null) { if (! is_integer($priority)) { - throw new \Zend\Log\Exception('Priority must be an integer'); + throw new \Zend\Log\Exception\InvalidArgumentException('Priority must be an integer'); } $this->_priority = $priority; @@ -70,7 +70,7 @@ public function __construct($priority, $operator = null) * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Filter\Priority - * @throws \Zend\Log\Exception + * @throws \Zend\Log\Exception\InvalidArgumentException */ static public function factory($config = array()) { @@ -86,7 +86,7 @@ static public function factory($config = array()) } if (!is_numeric($config['priority'])) { - throw new \Zend\Log\Exception('Priority must be an integer.'); + throw new \Zend\Log\Exception\InvalidArgumentException('Priority must be an integer.'); } return new self( diff --git a/src/Filter/SuppressFilter.php b/src/Filter/SuppressFilter.php index 5e2c2750..3c43bec3 100644 --- a/src/Filter/SuppressFilter.php +++ b/src/Filter/SuppressFilter.php @@ -71,7 +71,6 @@ public function accept($event) * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Filter\Suppress - * @throws \Zend\Log\Exception */ static public function factory($config = array()) { diff --git a/src/Formatter/Simple.php b/src/Formatter/Simple.php index 7a665d9e..d359f24f 100644 --- a/src/Formatter/Simple.php +++ b/src/Formatter/Simple.php @@ -27,7 +27,7 @@ use \Zend\Log\Formatter; /** - * @uses \Zend\Log\Exception + * @uses \Zend\Log\Exception\InvalidArgumentException * @uses \Zend\Log\Formatter\FormatterInterface * @category Zend * @package Zend_Log @@ -49,7 +49,7 @@ class Simple implements Formatter * Class constructor * * @param null|string $format Format specifier for log messages - * @throws \Zend\Log\Exception + * @throws \Zend\Log\Exception\InvalidArgumentException */ public function __construct($format = null) { @@ -58,7 +58,7 @@ public function __construct($format = null) } if (! is_string($format)) { - throw new \Zend\Log\Exception('Format must be a string'); + throw new \Zend\Log\Exception\InvalidArgumentException('Format must be a string'); } $this->_format = $format; diff --git a/src/Logger.php b/src/Logger.php index 3eb0cb89..db91a5b8 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -23,11 +23,13 @@ * @namespace */ namespace Zend\Log; + use Zend\Config\Config; /** * @uses \Zend\Loader - * @uses \Zend\Log\Exception + * @uses \Zend\Log\Exception\InvalidArgumentException + * @uses \Zend\Log\Exception\RuntimeException * @uses \Zend\Log\Filter\Priority * @category Zend * @package Zend_Log @@ -123,6 +125,7 @@ public function __construct(Writer $writer = null) * based on the configuration array * * @param array|\Zend\Config\Config Array or instance of \Zend\Config\Config + * @throws \Zend\Log\Exception\InvalidArgumentException * @return \Zend\Log\Logger */ static public function factory($config = array()) @@ -132,7 +135,7 @@ static public function factory($config = array()) } if (!is_array($config) || empty($config)) { - throw new Exception('Configuration must be an array or instance of Zend\\Config\\Config'); + throw new Exception\InvalidArgumentException('Configuration must be an array or instance of Zend\\Config\\Config'); } $log = new self; @@ -153,6 +156,7 @@ static public function factory($config = array()) * Construct a writer object based on a configuration array * * @param array $spec config array with writer spec + * @throws \Zend\Log\Exception\InvalidArgumentException * @return \Zend\Log\Writer\AbstractWriter */ protected function _constructWriterFromConfig($config) @@ -163,7 +167,7 @@ protected function _constructWriterFromConfig($config) $writerName = is_object($writer) ? get_class($writer) : 'The specified writer'; - throw new Exception("{$writerName} does not extend Zend\\Log\\Writer!"); + throw new Exception\InvalidArgumentException("{$writerName} does not extend Zend\\Log\\Writer!"); } if (isset($config['filterName'])) { @@ -178,6 +182,7 @@ protected function _constructWriterFromConfig($config) * Construct filter object from configuration array or Zend_Config object * * @param array|\Zend\Config\Config $config \Zend\Config\Config or Array + * @throws \Zend\Log\Exception\InvalidArgumentException * @return \Zend\Log\Filter */ protected function _constructFilterFromConfig($config) @@ -188,7 +193,7 @@ protected function _constructFilterFromConfig($config) $filterName = is_object($filter) ? get_class($filter) : 'The specified filter'; - throw new Exception("{$filterName} does not implement Zend\\Log\\Filter"); + throw new Exception\InvalidArgumentException("{$filterName} does not implement Zend\\Log\\Filter"); } return $filter; @@ -200,6 +205,7 @@ protected function _constructFilterFromConfig($config) * @param string $type 'writer' of 'filter' * @param mixed $config \Zend\Config\Config or Array * @param string $namespace + * @throws \Zend\Log\Exception\InvalidArgumentException * @return object */ protected function _constructFromConfig($type, $config, $namespace) @@ -209,7 +215,7 @@ protected function _constructFromConfig($type, $config, $namespace) } if (!is_array($config) || empty($config)) { - throw new Exception( + throw new Exception\InvalidArgumentException( 'Configuration must be an array or instance of Zend\\Config\\Config' ); } @@ -222,7 +228,7 @@ protected function _constructFromConfig($type, $config, $namespace) $reflection = new \ReflectionClass($className); if (!$reflection->implementsInterface('Zend\Log\Factory')) { - throw new Exception( + throw new Exception\InvalidArgumentException( 'Driver does not implement Zend\Log\Factory and can not be constructed from config.' ); } @@ -236,12 +242,13 @@ protected function _constructFromConfig($type, $config, $namespace) * @param array $config * @param string $type filter|writer * @param string $defaultNamespace + * @throws \Zend\Log\Exception\InvalidArgumentException * @return string full classname */ protected function getClassName($config, $type, $defaultNamespace) { if (!isset($config[ $type . 'Name' ])) { - throw new Exception("Specify {$type}Name in the configuration array"); + throw new Exception\InvalidArgumentException("Specify {$type}Name in the configuration array"); } $className = $config[ $type . 'Name' ]; @@ -294,7 +301,7 @@ public function __destruct() * @param string $method priority name * @param string $params message to log * @return void - * @throws \Zend\Log\Exception + * @throws \Zend\Log\Exception\InvalidArgumentException */ public function __call($method, $params) { @@ -302,7 +309,7 @@ public function __call($method, $params) if (($priority = array_search($priority, $this->_priorities)) !== false) { switch (count($params)) { case 0: - throw new Exception('Missing log message'); + throw new Exception\InvalidArgumentException('Missing log message'); case 1: $message = array_shift($params); $extras = null; @@ -314,7 +321,7 @@ public function __call($method, $params) } $this->log($message, $priority, $extras); } else { - throw new Exception('Bad log priority'); + throw new Exception\InvalidArgumentException('Bad log priority'); } } @@ -324,18 +331,19 @@ public function __call($method, $params) * @param string $message Message to log * @param integer $priority Priority of message * @param mixed $extras Extra information to log in event + * @throws \Zend\Log\Exception\InvalidArgumentException + * @throws \Zend\Log\Exception\RuntimeException * @return void - * @throws \Zend\Log\Exception */ public function log($message, $priority, $extras = null) { // sanity checks if (empty($this->_writers)) { - throw new Exception('No writers were added'); + throw new Exception\RuntimeException('No writers were added'); } if (! isset($this->_priorities[$priority])) { - throw new Exception('Bad log priority'); + throw new Exception\InvalidArgumentException('Bad log priority'); } // pack into event required by filters and writers @@ -378,7 +386,8 @@ public function log($message, $priority, $extras = null) * * @param string $name Name of priority * @param integer $priority Numeric priority - * @throws Zend_Log_InvalidArgumentException + * @throws \Zend\Log\Exception\InvalidArgumentException + * @return \Zend\Log\Logger */ public function addPriority($name, $priority) { @@ -387,7 +396,7 @@ public function addPriority($name, $priority) if (isset($this->_priorities[$priority]) || false !== array_search($name, $this->_priorities)) { - throw new Exception('Existing priorities cannot be overwritten'); + throw new Exception\InvalidArgumentException('Existing priorities cannot be overwritten'); } $this->_priorities[$priority] = $name; @@ -400,6 +409,7 @@ public function addPriority($name, $priority) * must be accepted by all filters added with this method. * * @param int|\Zend\Log\Filter\FilterInterface $filter + * @throws \Zend\Log\Exception\InvalidArgumentException * @return void */ public function addFilter($filter) @@ -411,7 +421,7 @@ public function addFilter($filter) $filter = $this->_constructFilterFromConfig($filter); } elseif(! $filter instanceof Filter) { - throw new Exception('Invalid filter provided'); + throw new Exception\InvalidArgumentException('Invalid filter provided'); } $this->_filters[] = $filter; @@ -423,6 +433,7 @@ public function addFilter($filter) * message and writing it out to storage. * * @param mixed $writer \Zend\Log\Writer\AbstractWriter or Config array + * @throws \Zend\Log\Exception\InvalidArgumentException * @return void */ public function addWriter($writer) @@ -432,7 +443,7 @@ public function addWriter($writer) } if (!$writer instanceof Writer) { - throw new Exception( + throw new Exception\InvalidArgumentException( 'Writer must be an instance of Zend\\Log\\Writer' . ' or you should pass a configuration array' ); diff --git a/src/Writer.php b/src/Writer.php index 0581b699..3d2a0b2d 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -26,7 +26,6 @@ namespace Zend\Log; /** - * @uses \Zend\Log\Exception * @uses \Zend\Log\FactoryInterface * @uses \Zend\Log\Filter\Priority * @category Zend diff --git a/src/Writer/AbstractWriter.php b/src/Writer/AbstractWriter.php index 411c7494..9ba391b2 100644 --- a/src/Writer/AbstractWriter.php +++ b/src/Writer/AbstractWriter.php @@ -29,7 +29,7 @@ \Zend\Log\Writer; /** - * @uses \Zend\Log\Exception + * @uses \Zend\Log\Exception\InvalidArgumentException * @uses \Zend\Log\Factory * @uses \Zend\Log\Filter\Priority * @category Zend @@ -56,6 +56,7 @@ abstract class AbstractWriter implements Writer, Factory * Add a filter specific to this writer. * * @param \Zend\Log\Filter $filter + * @throws \Zend\Log\Exception\InvalidArgumentException * @return void */ public function addFilter($filter) @@ -65,7 +66,7 @@ public function addFilter($filter) } if (!$filter instanceof \Zend\Log\Filter) { - throw new \Zend\Log\Exception('Invalid filter provided'); + throw new \Zend\Log\Exception\InvalidArgumentException('Invalid filter provided'); } $this->_filters[] = $filter; @@ -123,7 +124,7 @@ abstract protected function _write($event); * * @param array|\Zend\Config\Config $config \Zend\Config\Config or Array * @return array - * @throws \Zend\Log\Exception + * @throws \Zend\Log\Exception\InvalidArgumentException */ static protected function _parseConfig($config) { @@ -132,7 +133,7 @@ static protected function _parseConfig($config) } if (!is_array($config)) { - throw new \Zend\Log\Exception( + throw new \Zend\Log\Exception\InvalidArgumentException( 'Configuration must be an array or instance of Zend\\Config\\Config' ); } diff --git a/src/Writer/Db.php b/src/Writer/Db.php index 583d779c..f81a314c 100644 --- a/src/Writer/Db.php +++ b/src/Writer/Db.php @@ -27,7 +27,8 @@ use Zend\Log; /** - * @uses \Zend\Log\Exception + * @uses \Zend\Log\Exception\InvalidArgumentException + * @uses \Zend\Log\Exception\RuntimeException * @uses \Zend\Log\Writer\AbstractWriter * @category Zend * @package Zend_Log @@ -76,7 +77,6 @@ public function __construct($db, $table, $columnMap = null) * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Writer\Db - * @throws \Zend\Log\Exception */ static public function factory($config = array()) { @@ -100,10 +100,12 @@ static public function factory($config = array()) /** * Formatting is not possible on this writer + * + * @throws \Zend\Log\Exception\InvalidArgumentException */ public function setFormatter(\Zend\Log\Formatter $formatter) { - throw new Log\Exception(get_class() . ' does not support formatting'); + throw new Log\Exception\InvalidArgumentException(get_class() . ' does not support formatting'); } /** @@ -120,12 +122,13 @@ public function shutdown() * Write a message to the log. * * @param array $event event data + * @throws \Zend\Log\Exception\RuntimeException * @return void */ protected function _write($event) { if ($this->_db === null) { - throw new Log\Exception('Database adapter is null'); + throw new Log\Exception\RuntimeException('Database adapter is null'); } if ($this->_columnMap === null) { diff --git a/src/Writer/Firebug.php b/src/Writer/Firebug.php index 1f521b22..9a99f13a 100644 --- a/src/Writer/Firebug.php +++ b/src/Writer/Firebug.php @@ -85,7 +85,6 @@ public function __construct() * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Writer\Firebug - * @throws \Zend\Log\Exception */ static public function factory($config = array()) { diff --git a/src/Writer/Mail.php b/src/Writer/Mail.php index 04f5ed00..638e0043 100644 --- a/src/Writer/Mail.php +++ b/src/Writer/Mail.php @@ -33,7 +33,9 @@ * Zend_Mail object. Note that this class only sends the email upon * completion, so any log entries accumulated are sent in a single email. * - * @uses \Zend\Log\Exception + * @uses \Zend\Log\Exception\InvalidArgumentException + * @uses \Zend\Log\Exception\NotImplementedException + * @uses \Zend\Log\Exception\RuntimeException * @uses \Zend\Log\Formatter\Simple * @uses \Zend\Log\Writer\AbstractWriter * @category Zend @@ -123,11 +125,11 @@ public function __construct(\Zend\Mail\Mail $mail, \Zend\Layout\Layout $layout = * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Writer\Mail - * @throws \Zend\Log\Exception + * @throws \Zend\Log\Exception\NotImplementedException */ static public function factory($config = array()) { - throw new Log\Exception('Zend\\Log\\Writer\\Mail does not currently implement a factory'); + throw new Log\Exception\NotImplementedException('Zend\\Log\\Writer\\Mail does not currently implement a factory'); } /** @@ -186,12 +188,12 @@ public function getLayoutFormatter() * * @param \Zend\Log\Formatter\FormatterInterface $formatter * @return \Zend\Log\Writer\Mail - * @throws \Zend\Log\Exception + * @throws \Zend\Log\Exception\InvalidArgumentException */ public function setLayoutFormatter(Log\Formatter $formatter) { if (!$this->_layout) { - throw new Log\Exception( + throw new Log\Exception\InvalidArgumentException( 'cannot set formatter for layout; ' . 'a Zend_Layout instance is not in use'); } @@ -210,12 +212,13 @@ public function setLayoutFormatter(Log\Formatter $formatter) * subject set. * * @param string $subject Subject prepend text. + * @throws \Zend\Log\Exception\RuntimeException * @return \Zend\Log\Writer\Mail */ public function setSubjectPrependText($subject) { if ($this->_mail->getSubject()) { - throw new Log\Exception( + throw new Log\Exception\RuntimeException( 'subject already set on mail; ' . 'cannot set subject prepend text'); } diff --git a/src/Writer/Mock.php b/src/Writer/Mock.php index 767aabbf..e4128073 100644 --- a/src/Writer/Mock.php +++ b/src/Writer/Mock.php @@ -72,7 +72,6 @@ public function shutdown() * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Writer\Mock - * @throws \Zend\Log\Exception */ static public function factory($config = array()) { diff --git a/src/Writer/Null.php b/src/Writer/Null.php index e3bd6dd5..fd89cb7b 100644 --- a/src/Writer/Null.php +++ b/src/Writer/Null.php @@ -51,7 +51,6 @@ protected function _write($event) * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Writer\Null - * @throws \Zend\Log\Exception */ static public function factory($config = array()) { diff --git a/src/Writer/Stream.php b/src/Writer/Stream.php index 35ea0b45..b8228471 100644 --- a/src/Writer/Stream.php +++ b/src/Writer/Stream.php @@ -27,7 +27,7 @@ use Zend\Log; /** - * @uses \Zend\Log\Exception + * @uses \Zend\Log\Exception\InvalidArgumentException * @uses \Zend\Log\Formatter\Simple * @uses \Zend\Log\Writer\AbstractWriter * @category Zend @@ -50,6 +50,8 @@ class Stream extends AbstractWriter * * @param streamOrUrl Stream or URL to open as a stream * @param mode Mode, only applicable if a URL is given + * @throws \Zend\Log\Exception\InvalidArgumentException + * @throws \Zend\Log\Excpeiton\RuntimeException */ public function __construct($streamOrUrl, $mode = \NULL) { @@ -60,11 +62,11 @@ public function __construct($streamOrUrl, $mode = \NULL) if (is_resource($streamOrUrl)) { if (get_resource_type($streamOrUrl) != 'stream') { - throw new Log\Exception('Resource is not a stream'); + throw new Log\Exception\InvalidArgumentException('Resource is not a stream'); } if ($mode != 'a') { - throw new Log\Exception('Mode cannot be changed on existing streams'); + throw new Log\Exception\InvalidArgumentException('Mode cannot be changed on existing streams'); } $this->_stream = $streamOrUrl; @@ -75,7 +77,7 @@ public function __construct($streamOrUrl, $mode = \NULL) if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) { $msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\""; - throw new Log\Exception($msg); + throw new Log\Exception\RuntimeException($msg); } } @@ -87,7 +89,6 @@ public function __construct($streamOrUrl, $mode = \NULL) * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Writer\Mock - * @throws \Zend\Log\Exception */ public static function factory($config = array()) { @@ -121,6 +122,7 @@ public function shutdown() * Write a message to the log. * * @param array $event event data + * @throws \Zend\Log\Exception\RuntimeException * @return void */ protected function _write($event) @@ -128,7 +130,7 @@ protected function _write($event) $line = $this->_formatter->format($event); if (false === @fwrite($this->_stream, $line)) { - throw new Log\Exception("Unable to write to stream"); + throw new Log\Exception\RuntimeException("Unable to write to stream"); } } } diff --git a/src/Writer/Syslog.php b/src/Writer/Syslog.php index 5a50edc6..855d61d4 100644 --- a/src/Writer/Syslog.php +++ b/src/Writer/Syslog.php @@ -30,6 +30,7 @@ * Writes log messages to syslog * * @uses \Zend\Log\Log + * @uses \Zend\Log\Exception\InvalidArgumentException * @uses \Zend\Log\Writer\AbstractWriter * @category Zend * @package Zend_Log @@ -119,7 +120,6 @@ public function __construct(array $params = array()) * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Writer\Syslog - * @throws \Zend\Log\Exception */ static public function factory($config = array()) { @@ -179,7 +179,7 @@ protected function _initializeSyslog() * * @param int $facility Syslog facility * @return void - * @throws Zend_Log_Exception for invalid log facility + * @throws \Zend\Log\Exception\InvalidArgumentException for invalid log facility */ public function setFacility($facility) { @@ -192,13 +192,15 @@ public function setFacility($facility) } if (!in_array($facility, $this->_validFacilities)) { - throw new Log\Exception('Invalid log facility provided; please see http://php.net/openlog for a list of valid facility values'); + throw new Log\Exception\InvalidArgumentException( + 'Invalid log facility provided; please see http://php.net/openlog for a list of valid facility values' + ); } if ('WIN' == strtoupper(substr(PHP_OS, 0, 3)) && ($facility !== LOG_USER) ) { - throw new Log\Exception('Only LOG_USER is a valid log facility on Windows'); + throw new Log\Exception\InvalidArgumentException('Only LOG_USER is a valid log facility on Windows'); } $this->_facility = $facility; diff --git a/src/Writer/ZendMonitor.php b/src/Writer/ZendMonitor.php index 0548fa4a..efd592c6 100644 --- a/src/Writer/ZendMonitor.php +++ b/src/Writer/ZendMonitor.php @@ -43,7 +43,6 @@ class ZendMonitor extends AbstractWriter protected $_isEnabled = true; /** - * @throws \Zend\Log\Exception if Zend Monitor extension not present */ public function __construct() { @@ -57,7 +56,6 @@ public function __construct() * * @param array|\Zend\Config\Config $config * @return \Zend\Log\Writer\Syslog - * @throws \Zend\Log\Exception */ static public function factory($config = array()) { diff --git a/test/Filter/MessageTest.php b/test/Filter/MessageTest.php index f35decff..85eb893f 100644 --- a/test/Filter/MessageTest.php +++ b/test/Filter/MessageTest.php @@ -38,7 +38,7 @@ class MessageTest extends \PHPUnit_Framework_TestCase { public function testMessageFilterRecognizesInvalidRegularExpression() { - $this->setExpectedException('\\Zend\\Log\\Exception', 'invalid reg'); + $this->setExpectedException('\\Zend\\Log\\Exception\\InvalidArgumentException', 'invalid reg'); $filter = new Message('invalid regexp'); } diff --git a/test/Filter/PriorityTest.php b/test/Filter/PriorityTest.php index 60a3ff57..1c63019b 100644 --- a/test/Filter/PriorityTest.php +++ b/test/Filter/PriorityTest.php @@ -57,7 +57,7 @@ public function testComparisonOperatorCanBeChanged() public function testConstructorThrowsOnInvalidPriority() { - $this->setExpectedException('\\Zend\\Log\\Exception', 'must be an integer'); + $this->setExpectedException('\Zend\Log\Exception\InvalidArgumentException', 'must be an integer'); new Priority('foo'); } @@ -78,7 +78,7 @@ public function testFactory() public function testFactoryRaisesExceptionWithInvalidPriority() { - $this->setExpectedException('\Zend\Log\Exception', 'must be an integer'); + $this->setExpectedException('\Zend\Log\Exception\InvalidArgumentException', 'must be an integer'); $logger = Logger::factory(array('Null' => array( 'writerName' => 'Mock', 'filterName' => 'Priority', diff --git a/test/Formatter/SimpleTest.php b/test/Formatter/SimpleTest.php index 3a8f831b..2dab24e5 100644 --- a/test/Formatter/SimpleTest.php +++ b/test/Formatter/SimpleTest.php @@ -36,7 +36,7 @@ class SimpleTest extends \PHPUnit_Framework_TestCase { public function testConstructorThrowsOnBadFormatString() { - $this->setExpectedException('\\Zend\\Log\\Exception', 'must be a string'); + $this->setExpectedException('\Zend\Log\Exception\InvalidArgumentException', 'must be a string'); new Simple(1); } diff --git a/test/LoggerTest.php b/test/LoggerTest.php index 0c6a3b6c..c9f422cc 100644 --- a/test/LoggerTest.php +++ b/test/LoggerTest.php @@ -96,7 +96,7 @@ public function testAddWriterAddsMultipleWriters() public function testLoggerThrowsWhenNoWriters() { - $this->setExpectedException('Zend\Log\Exception', 'No writers'); + $this->setExpectedException('Zend\Log\Exception\RuntimeException', 'No writers'); $logger = new Logger(); $logger->log('message', Logger::INFO); } @@ -125,7 +125,7 @@ public function testLogThrowsOnBadLogPriority() { $logger = new Logger($this->writer); - $this->setExpectedException('Zend\Log\Exception', 'Bad log priority'); + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Bad log priority'); $logger->log('foo', 42); } @@ -133,13 +133,13 @@ public function testLogThrough__callThrowsOnBadLogPriority() { $logger = new Logger($this->writer); - $this->setExpectedException('Zend\Log\Exception', 'Bad log priority'); + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Bad log priority'); $logger->nonexistantPriority(''); } public function testAddingPriorityThrowsWhenOverridingBuiltinLogPriority() { - $this->setExpectedException('Zend\Log\Exception', 'Existing priorities'); + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Existing priorities'); $logger = new Logger($this->writer); $logger->addPriority('BOB', 0); } @@ -359,7 +359,7 @@ public function testExceptionConstructWriterFromConfig() $writer = array('writerName' => 'NotExtendedWriterAbstract'); $logger->addWriter($writer); } catch (\Exception $e) { - $this->assertType('Zend\Log\Exception', $e); + $this->assertType('Zend\Log\Exception\InvalidArgumentException', $e); $this->assertRegExp('#^(Zend\\\\Log\\\\Writer\\\\NotExtendedWriterAbstract|The\sspecified\swriter)#', $e->getMessage()); } } @@ -374,7 +374,7 @@ public function testExceptionConstructFilterFromConfig() $filter = array('filterName' => 'NotImplementsFilterInterface'); $logger->addFilter($filter); } catch (\Exception $e) { - $this->assertType('Zend\Log\Exception', $e); + $this->assertType('Zend\Log\Exception\InvalidArgumentException', $e); $this->assertRegExp('#^(Zend\\\\Log\\\\Filter\\\\NotImplementsFilterInterface|The\sspecified\sfilter)#', $e->getMessage()); } } @@ -405,7 +405,7 @@ public function testPriorityDuplicates() $logger->addPriority('emerg', 8); $this->fail(); } catch(\Exception $e) { - $this->assertType('Zend\Log\Exception', $e); + $this->assertType('Zend\Log\Exception\InvalidArgumentException', $e); $this->assertEquals('Existing priorities cannot be overwritten', $e->getMessage()); } @@ -414,7 +414,7 @@ public function testPriorityDuplicates() $logger->log('clone zf10170', 8); $this->fail(); } catch (\Exception $e) { - $this->assertType('Zend\Log\Exception', $e); + $this->assertType('Zend\Log\Exception\InvalidArgumentException', $e); $this->assertEquals('Bad log priority', $e->getMessage()); } $this->assertEquals(0, $mock->events[0]['priority']); diff --git a/test/Writer/AbstractTest.php b/test/Writer/AbstractTest.php index 543b991e..a1c48299 100644 --- a/test/Writer/AbstractTest.php +++ b/test/Writer/AbstractTest.php @@ -57,7 +57,7 @@ public function testAddFilter() { $this->_writer->addFilter(1); $this->_writer->addFilter(new MessageFilter('/mess/')); - $this->setExpectedException('Zend\Log\Exception'); + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException'); $this->_writer->addFilter(new \StdClass()); } diff --git a/test/Writer/DbTest.php b/test/Writer/DbTest.php index 3d2075f4..d9430cb5 100644 --- a/test/Writer/DbTest.php +++ b/test/Writer/DbTest.php @@ -45,7 +45,7 @@ public function setUp() public function testFormattingIsNotSupported() { - $this->setExpectedException('\\Zend\\Log\\Exception', 'does not support formatting'); + $this->setExpectedException('\Zend\Log\Exception\InvalidArgumentException', 'does not support formatting'); $this->writer->setFormatter(new \Zend\Log\Formatter\Simple); } @@ -95,7 +95,7 @@ public function testShutdownRemovesReferenceToDatabaseInstance() $this->writer->write(array('message' => 'this should not fail')); $this->writer->shutdown(); - $this->setExpectedException('\\Zend\\Log\\Exception', 'Database adapter is null'); + $this->setExpectedException('\Zend\Log\Exception\RuntimeException', 'Database adapter is null'); $this->writer->write(array('message' => 'this should fail')); } diff --git a/test/Writer/MailTest.php b/test/Writer/MailTest.php index 5e9f6a66..85791b28 100644 --- a/test/Writer/MailTest.php +++ b/test/Writer/MailTest.php @@ -138,7 +138,7 @@ public function testSetSubjectPrependTextPreExisting() // Expect a Zend_Log_Exception because the subject prepend text cannot // be set of the Zend_Mail object already has a subject line set. - $this->setExpectedException('Zend\Log\Exception'); + $this->setExpectedException('Zend\Log\Exception\RuntimeException'); // Set a subject line so the setSubjectPrependText() call triggers an // exception. @@ -189,7 +189,7 @@ public function testSetLayoutFormatterWithoutLayout() list(, $writer) = $this->_getSimpleLogger(); // If Zend_Layout is not being used, a formatter cannot be set for it. - $this->setExpectedException('Zend\Log\Exception'); + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException'); $writer->setLayoutFormatter(new SimpleFormatter()); } diff --git a/test/Writer/StreamTest.php b/test/Writer/StreamTest.php index 4d169318..7275b3fa 100644 --- a/test/Writer/StreamTest.php +++ b/test/Writer/StreamTest.php @@ -43,7 +43,7 @@ public function testConstructorThrowsWhenResourceIsNotStream() new StreamWriter($resource); $this->fail(); } catch (\Exception $e) { - $this->assertType('\\Zend\\Log\\Exception', $e); + $this->assertType('\Zend\Log\Exception\InvalidArgumentException', $e); $this->assertRegExp('/not a stream/i', $e->getMessage()); } xml_parser_free($resource); @@ -63,13 +63,13 @@ public function testConstructorWithValidUrl() public function testConstructorThrowsWhenModeSpecifiedForExistingStream() { $stream = fopen('php://memory', 'w+'); - $this->setExpectedException('\\Zend\\Log\\Exception', 'existing stream'); + $this->setExpectedException('\Zend\Log\Exception\InvalidArgumentException', 'existing stream'); new StreamWriter($stream, 'w+'); } public function testConstructorThrowsWhenStreamCannotBeOpened() { - $this->setExpectedException('\\Zend\\Log\\Exception', 'cannot be opened'); + $this->setExpectedException('\Zend\Log\Exception\RuntimeException', 'cannot be opened'); new StreamWriter(''); } @@ -94,7 +94,7 @@ public function testWriteThrowsWhenStreamWriteFails() $writer = new StreamWriter($stream); fclose($stream); - $this->setExpectedException('\\Zend\\Log\\Exception', 'Unable to write'); + $this->setExpectedException('\Zend\Log\Exception\RuntimeException', 'Unable to write'); $writer->write(array('message' => 'foo')); } @@ -105,7 +105,7 @@ public function testShutdownClosesStreamResource() $writer->shutdown(); - $this->setExpectedException('\\Zend\\Log\\Exception', 'Unable to write'); + $this->setExpectedException('\Zend\Log\Exception\RuntimeException', 'Unable to write'); $writer->write(array('message' => 'this write should fail')); } diff --git a/test/Writer/SyslogTest.php b/test/Writer/SyslogTest.php index 8c157dfd..7a421ea9 100644 --- a/test/Writer/SyslogTest.php +++ b/test/Writer/SyslogTest.php @@ -57,7 +57,7 @@ public function testFactory() */ public function testThrowExceptionValueNotPresentInFacilities() { - $this->setExpectedException('Zend\Log\Exception', 'Invalid log facility provided'); + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Invalid log facility provided'); $writer = new SyslogWriter(); $writer->setFacility(LOG_USER * 1000); } @@ -70,7 +70,7 @@ public function testThrowExceptionIfFacilityInvalidInWindows() if ('WIN' != strtoupper(substr(PHP_OS, 0, 3))) { $this->markTestSkipped('Run only in windows'); } - $this->setExpectedException('Zend\Log\Exception', 'Only LOG_USER is a valid'); + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Only LOG_USER is a valid'); $writer = new SyslogWriter(); $writer->setFacility(LOG_AUTH); } From cf8b9cd8fb8ef9c8ebc787a5dde2e98308b1037b Mon Sep 17 00:00:00 2001 From: sasa Date: Tue, 5 Oct 2010 01:23:28 +0200 Subject: [PATCH 2/2] refactored Zend\Log for exceptions milestone --- src/Logger.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Logger.php b/src/Logger.php index db91a5b8..f86195fc 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -106,8 +106,7 @@ class Logger implements Factory protected $_timestampFormat = 'c'; /** - * Class constructor. Create a new logger - * + * Class constructor. Create a new logger * * @param \Zend\Log\Writer\AbstractWriter|null $writer default writer */ public function __construct(Writer $writer = null)