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

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkael committed Jul 22, 2010
6 parents ce0f62a + ca34104 + 829cfe1 + dea5efb + 7e2c3cc + 307038c commit 2d857f5
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,12 @@ public function addPriority($name, $priority)
$name = strtoupper($name);

if (isset($this->_priorities[$priority])
|| array_search($name, $this->_priorities)) {
|| false !== array_search($name, $this->_priorities)) {
throw new Exception('Existing priorities cannot be overwritten');
}

$this->_priorities[$priority] = $name;
return $this;
}

/**
Expand All @@ -414,6 +415,7 @@ public function addFilter($filter)
}

$this->_filters[] = $filter;
return $this;
}

/**
Expand All @@ -437,6 +439,7 @@ public function addWriter($writer)
}

$this->_writers[] = $writer;
return $this;
}

/**
Expand All @@ -449,6 +452,7 @@ public function addWriter($writer)
public function setEventItem($name, $value)
{
$this->_extras = array_merge($this->_extras, array($name => $value));
return $this;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function addFilter($filter)
}

$this->_filters[] = $filter;
return $this;
}

/**
Expand Down Expand Up @@ -98,6 +99,7 @@ public function write($event)
public function setFormatter($formatter)
{
$this->_formatter = $formatter;
return $this;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Writer/Syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function _initializeSyslog()
public function setFacility($facility)
{
if ($this->_facility === $facility) {
return;
return $this;
}

if (!count($this->_validFacilities)) {
Expand All @@ -205,6 +205,7 @@ public function setFacility($facility)

$this->_facility = $facility;
$this->_initializeSyslog();
return $this;
}

/**
Expand All @@ -216,10 +217,11 @@ public function setFacility($facility)
public function setApplicationName($application)
{
if ($this->_application === $application) {
return;
return $this;
}
$this->_application = $application;
$this->_initializeSyslog();
return $this;
}

/**
Expand Down
43 changes: 43 additions & 0 deletions test/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,47 @@ public function testExceptionConstructFilterFromConfig()
$this->assertRegExp('#^(Zend\\\\Log\\\\Filter\\\\NotImplementsFilterInterface|The\sspecified\sfilter)#', $e->getMessage());
}
}

/**
* @group ZF-8953
*/
public function testFluentInterface()
{
$logger = new Zend_Log();
$instance = $logger->addPriority('all', 8)
->addFilter(1)
->addWriter(array('writerName' => 'Null'))
->setEventItem('os', PHP_OS);

$this->assertTrue($instance instanceof Zend_Log);
}

/**
* @group ZF-10170
*/
public function testPriorityDuplicates()
{
$logger = new Zend_Log();
$mock = new Zend_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->assertEquals(0, $mock->events[0]['priority']);
$this->assertEquals('EMERG', $mock->events[0]['priorityName']);
$this->assertFalse(array_key_exists(1, $mock->events));
}
}
12 changes: 12 additions & 0 deletions test/Writer/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ public function testAddFilter()
$this->setExpectedException('Zend_Log_Exception');
$this->_writer->addFilter(new StdClass());
}

/**
* @group ZF-8953
*/
public function testFluentInterface()
{
require_once 'Zend/Log/Formatter/Simple.php';
$instance = $this->_writer->addFilter(1)
->setFormatter(new Zend_Log_Formatter_Simple());

$this->assertTrue($instance instanceof Zend_Log_Writer_AbstractTest_Concrete);
}
}

class Zend_Log_Writer_AbstractTest_Concrete extends Zend_Log_Writer_Abstract
Expand Down
13 changes: 13 additions & 0 deletions test/Writer/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ public function testDestructorLayoutError()
unset($log);
}

/**
* @group ZF-8953
*/
public function testFluentInterface()
{
require_once 'Zend/Log/Formatter/Simple.php';
list(, $writer) = $this->_getSimpleLogger(true);
$instance = $writer->setLayoutFormatter(new Zend_Log_Formatter_Simple())
->setSubjectPrependText('subject');

$this->assertTrue($instance instanceof Zend_Log_Writer_Mail);
}

/**
* Returns an array of the Zend_Mail mock object, Zend_Log_Writer_Mail
* object, and Zend_Log objects.
Expand Down
12 changes: 12 additions & 0 deletions test/Writer/SyslogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,16 @@ public function testThrowExceptionIfFacilityInvalidInWindows()
$this->assertContains('Only LOG_USER is a valid', $e->getMessage());
}
}

/**
* @group ZF-8953
*/
public function testFluentInterface()
{
$writer = new Zend_Log_Writer_Syslog();
$instance = $writer->setFacility(LOG_USER)
->setApplicationName('my_app');

$this->assertTrue($instance instanceof Zend_Log_Writer_Syslog);
}
}

0 comments on commit 2d857f5

Please sign in to comment.