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..3fe00bf9 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 @@ -104,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) @@ -123,6 +124,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 +134,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 +155,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 +166,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 +181,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 +192,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 +204,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,8 +214,8 @@ protected function _constructFromConfig($type, $config, $namespace) } 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' ); } @@ -222,7 +227,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 +241,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 +300,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 +308,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 +320,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 +330,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 +385,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 +395,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 +408,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 +420,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 +432,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,8 +442,8 @@ public function addWriter($writer) } if (!$writer instanceof Writer) { - throw new Exception( - 'Writer must be an instance of Zend\\Log\\Writer' + 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..b7169ba2 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,8 +133,8 @@ static protected function _parseConfig($config) } if (!is_array($config)) { - throw new \Zend\Log\Exception( - 'Configuration must be an array or instance of Zend\\Config\\Config' + 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..54039e1c 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,14 +188,14 @@ 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'); + 'a Zend\Layout\Layout instance is not in use'); } $this->_layoutFormatter = $formatter; @@ -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..a6338747 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..0ad4015b 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..6b25708c 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..40fe64e1 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); } @@ -354,14 +354,11 @@ public function testLogWritesWithModifiedTimestampFormat() */ public function testExceptionConstructWriterFromConfig() { - try { - $logger = new Logger(); - $writer = array('writerName' => 'NotExtendedWriterAbstract'); - $logger->addWriter($writer); - } catch (\Exception $e) { - $this->assertType('Zend\Log\Exception', $e); - $this->assertRegExp('#^(Zend\\\\Log\\\\Writer\\\\NotExtendedWriterAbstract|The\sspecified\swriter)#', $e->getMessage()); - } + $logger = new Logger(); + $writer = array('writerName' => 'NotExtendedWriterAbstract'); + + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'The specified writer does not extend Zend\Log\Writer'); + $logger->addWriter($writer); } /** @@ -369,14 +366,11 @@ public function testExceptionConstructWriterFromConfig() */ public function testExceptionConstructFilterFromConfig() { - try { - $logger = new Logger(); - $filter = array('filterName' => 'NotImplementsFilterInterface'); - $logger->addFilter($filter); - } catch (\Exception $e) { - $this->assertType('Zend\Log\Exception', $e); - $this->assertRegExp('#^(Zend\\\\Log\\\\Filter\\\\NotImplementsFilterInterface|The\sspecified\sfilter)#', $e->getMessage()); - } + $logger = new Logger(); + $filter = array('filterName' => 'NotImplementsFilterInterface'); + + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'The specified filter does not implement Zend\Log\Filter'); + $logger->addFilter($filter); } /** @@ -396,29 +390,31 @@ public function testFluentInterface() /** * @group ZF-10170 */ - public function testPriorityDuplicates() + public function testExceptionIsThrownOnPriorityDuplicates() { $logger = new Logger(); $mock = new Log\Writer\Mock(); $logger->addWriter($mock); - try { - $logger->addPriority('emerg', 8); - $this->fail(); - } catch(\Exception $e) { - $this->assertType('Zend\Log\Exception', $e); - $this->assertEquals('Existing priorities cannot be overwritten', $e->getMessage()); - } - - try { - $logger->log('zf10170', 0); - $logger->log('clone zf10170', 8); - $this->fail(); - } catch (\Exception $e) { - $this->assertType('Zend\Log\Exception', $e); - $this->assertEquals('Bad log priority', $e->getMessage()); - } + + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Existing priorities cannot be overwritten'); + $logger->addPriority('emerg', 8); + } + + /** + * @group ZF-10170 + */ + public function testExceptionIsThrownOnInvalidLogPriority() + { + $logger = new Logger(); + $mock = new Log\Writer\Mock(); + $logger->addWriter($mock); + $logger->log('zf10170', 0); + $this->assertEquals(0, $mock->events[0]['priority']); $this->assertEquals('EMERG', $mock->events[0]['priorityName']); $this->assertFalse(array_key_exists(1, $mock->events)); + + $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Bad log priority'); + $logger->log('clone zf10170', 8); } } 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..b1602bf8 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')); } @@ -119,12 +119,7 @@ public function testFactory() public function testThrowStrictSetFormatter() { $this->setExpectedException('PHPUnit_Framework_Error'); -// try { - $this->writer->setFormatter(new \StdClass()); -// } catch (Exception $e) { -// $this->assertType('PHPUnit_Framework_Error', $e); -// $this->assertContains('must implement interface', $e->getMessage()); -// } + $this->writer->setFormatter(new \StdClass()); } } 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..e850a948 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 old mode 100755 new mode 100644 index 8c157dfd..7a421ea9 --- 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); } diff --git a/test/Writer/ZendMonitorTest.php b/test/Writer/ZendMonitorTest.php old mode 100755 new mode 100644