Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Miletone/Exceptions
Browse files Browse the repository at this point in the history
- Cleaned up names & tests in Zend\Log for merge
  • Loading branch information
Ralph Schindler committed Oct 5, 2010
2 parents cf8b9cd + 49f0790 commit 3894dbf
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/Filter/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static protected function _parseConfig($config)
}

if (!is_array($config)) {
throw new \Zend\Log\Exception\InvalidArgumentException('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');
}

return $config;
Expand Down
4 changes: 2 additions & 2 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected function _constructFromConfig($type, $config, $namespace)

if (!is_array($config) || empty($config)) {
throw new Exception\InvalidArgumentException(
'Configuration must be an array or instance of Zend\\Config\\Config'
'Configuration must be an array or instance of Zend\Config\Config'
);
}

Expand Down Expand Up @@ -443,7 +443,7 @@ public function addWriter($writer)

if (!$writer instanceof Writer) {
throw new Exception\InvalidArgumentException(
'Writer must be an instance of Zend\\Log\\Writer'
'Writer must be an instance of Zend\Log\Writer'
. ' or you should pass a configuration array'
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static protected function _parseConfig($config)

if (!is_array($config)) {
throw new \Zend\Log\Exception\InvalidArgumentException(
'Configuration must be an array or instance of Zend\\Config\\Config'
'Configuration must be an array or instance of Zend\Config\Config'
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Writer/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function __construct(\Zend\Mail\Mail $mail, \Zend\Layout\Layout $layout =
*/
static public function factory($config = array())
{
throw new Log\Exception\NotImplementedException('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');
}

/**
Expand Down Expand Up @@ -195,7 +195,7 @@ public function setLayoutFormatter(Log\Formatter $formatter)
if (!$this->_layout) {
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;
Expand Down
2 changes: 1 addition & 1 deletion test/Filter/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MessageTest extends \PHPUnit_Framework_TestCase
{
public function testMessageFilterRecognizesInvalidRegularExpression()
{
$this->setExpectedException('\\Zend\\Log\\Exception\\InvalidArgumentException', 'invalid reg');
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'invalid reg');
$filter = new Message('invalid regexp');
}

Expand Down
4 changes: 2 additions & 2 deletions test/Filter/PriorityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testComparisonOperatorCanBeChanged()

public function testConstructorThrowsOnInvalidPriority()
{
$this->setExpectedException('\Zend\Log\Exception\InvalidArgumentException', 'must be an integer');
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'must be an integer');
new Priority('foo');
}

Expand All @@ -78,7 +78,7 @@ public function testFactory()

public function testFactoryRaisesExceptionWithInvalidPriority()
{
$this->setExpectedException('\Zend\Log\Exception\InvalidArgumentException', 'must be an integer');
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'must be an integer');
$logger = Logger::factory(array('Null' => array(
'writerName' => 'Mock',
'filterName' => 'Priority',
Expand Down
2 changes: 1 addition & 1 deletion test/Formatter/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SimpleTest extends \PHPUnit_Framework_TestCase
{
public function testConstructorThrowsOnBadFormatString()
{
$this->setExpectedException('\Zend\Log\Exception\InvalidArgumentException', 'must be a string');
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'must be a string');
new Simple(1);
}

Expand Down
62 changes: 29 additions & 33 deletions test/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,29 +354,23 @@ 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\InvalidArgumentException', $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);
}

/**
* @group ZF-9956
*/
public function testExceptionConstructFilterFromConfig()
{
try {
$logger = new Logger();
$filter = array('filterName' => 'NotImplementsFilterInterface');
$logger->addFilter($filter);
} catch (\Exception $e) {
$this->assertType('Zend\Log\Exception\InvalidArgumentException', $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);
}

/**
Expand All @@ -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\InvalidArgumentException', $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\InvalidArgumentException', $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);
}
}
11 changes: 3 additions & 8 deletions test/Writer/DbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function setUp()

public function testFormattingIsNotSupported()
{
$this->setExpectedException('\Zend\Log\Exception\InvalidArgumentException', 'does not support formatting');
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'does not support formatting');
$this->writer->setFormatter(new \Zend\Log\Formatter\Simple);
}

Expand Down Expand Up @@ -95,7 +95,7 @@ public function testShutdownRemovesReferenceToDatabaseInstance()
$this->writer->write(array('message' => 'this should not fail'));
$this->writer->shutdown();

$this->setExpectedException('\Zend\Log\Exception\RuntimeException', 'Database adapter is null');
$this->setExpectedException('Zend\Log\Exception\RuntimeException', 'Database adapter is null');
$this->writer->write(array('message' => 'this should fail'));
}

Expand All @@ -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());
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/Writer/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testConstructorThrowsWhenResourceIsNotStream()
new StreamWriter($resource);
$this->fail();
} catch (\Exception $e) {
$this->assertType('\Zend\Log\Exception\InvalidArgumentException', $e);
$this->assertType('Zend\Log\Exception\InvalidArgumentException', $e);
$this->assertRegExp('/not a stream/i', $e->getMessage());
}
xml_parser_free($resource);
Expand All @@ -63,13 +63,13 @@ public function testConstructorWithValidUrl()
public function testConstructorThrowsWhenModeSpecifiedForExistingStream()
{
$stream = fopen('php://memory', 'w+');
$this->setExpectedException('\Zend\Log\Exception\InvalidArgumentException', 'existing stream');
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'existing stream');
new StreamWriter($stream, 'w+');
}

public function testConstructorThrowsWhenStreamCannotBeOpened()
{
$this->setExpectedException('\Zend\Log\Exception\RuntimeException', 'cannot be opened');
$this->setExpectedException('Zend\Log\Exception\RuntimeException', 'cannot be opened');
new StreamWriter('');
}

Expand All @@ -94,7 +94,7 @@ public function testWriteThrowsWhenStreamWriteFails()
$writer = new StreamWriter($stream);
fclose($stream);

$this->setExpectedException('\Zend\Log\Exception\RuntimeException', 'Unable to write');
$this->setExpectedException('Zend\Log\Exception\RuntimeException', 'Unable to write');
$writer->write(array('message' => 'foo'));
}

Expand All @@ -105,7 +105,7 @@ public function testShutdownClosesStreamResource()

$writer->shutdown();

$this->setExpectedException('\Zend\Log\Exception\RuntimeException', 'Unable to write');
$this->setExpectedException('Zend\Log\Exception\RuntimeException', 'Unable to write');
$writer->write(array('message' => 'this write should fail'));
}

Expand Down

0 comments on commit 3894dbf

Please # to comment.