Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Merge r25246 to 1.12 release branch
Browse files Browse the repository at this point in the history
  • Loading branch information
frosch committed Feb 1, 2013
1 parent fdef766 commit 2882bc7
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 7 deletions.
10 changes: 6 additions & 4 deletions library/Zend/Log/Writer/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract
*
* @var Zend_Db_Adapter
*/
private $_db;
protected $_db;

/**
* Name of the log table in the database
*
* @var string
*/
private $_table;
protected $_table;

/**
* Relates database columns names to log data field keys.
*
* @var null|array
*/
private $_columnMap;
protected $_columnMap;

/**
* Class constructor
Expand Down Expand Up @@ -136,7 +136,9 @@ protected function _write($event)
} else {
$dataToInsert = array();
foreach ($this->_columnMap as $columnName => $fieldKey) {
$dataToInsert[$columnName] = $event[$fieldKey];
if (isset($event[$fieldKey])) {
$dataToInsert[$columnName] = $event[$fieldKey];
}
}
}

Expand Down
81 changes: 78 additions & 3 deletions tests/Zend/Log/Writer/DbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testFormattingIsNotSupported()
$this->writer->setFormatter(new Zend_Log_Formatter_Simple());
$this->fail();
} catch (Exception $e) {
$this->assertType('Zend_Log_Exception', $e);
$this->assertTrue($e instanceof Zend_Log_Exception);
$this->assertRegExp('/does not support formatting/i', $e->getMessage());
}
}
Expand Down Expand Up @@ -113,7 +113,7 @@ public function testShutdownRemovesReferenceToDatabaseInstance()
$this->writer->write(array('message' => 'this should fail'));
$this->fail();
} catch (Exception $e) {
$this->assertType('Zend_Log_Exception', $e);
$this->assertTrue($e instanceof Zend_Log_Exception);
$this->assertEquals('Database adapter is null', $e->getMessage());
}
}
Expand Down Expand Up @@ -141,10 +141,85 @@ public function testThrowStrictSetFormatter()
try {
$this->writer->setFormatter(new StdClass());
} catch (Exception $e) {
$this->assertType('PHPUnit_Framework_Error', $e);
$this->assertTrue($e instanceof PHPUnit_Framework_Error);
$this->assertContains('must implement interface', $e->getMessage());
}
}

/**
* @group ZF-12514
*/
public function testWriteWithExtraInfos()
{
// Init writer
$this->writer = new Zend_Log_Writer_Db(
$this->db, $this->tableName,
array(
'message-field' => 'message',
'priority-field' => 'priority',
'info-field' => 'info',
)
);

// Log
$message = 'message-to-log';
$priority = 2;
$info = 'extra-info';
$this->writer->write(
array(
'message' => $message,
'priority' => $priority,
'info' => $info,
)
);

// Test
$binds = array(
'message-field' => $message,
'priority-field' => $priority,
'info-field' => $info,
);
$this->assertEquals(
array($this->tableName, $binds),
$this->db->calls['insert'][0]
);
}

/**
* @group ZF-12514
*/
public function testWriteWithoutExtraInfos()
{
// Init writer
$this->writer = new Zend_Log_Writer_Db(
$this->db, $this->tableName,
array(
'message-field' => 'message',
'priority-field' => 'priority',
'info-field' => 'info',
)
);

// Log
$message = 'message-to-log';
$priority = 2;
$this->writer->write(
array(
'message' => $message,
'priority' => $priority,
)
);

// Test
$binds = array(
'message-field' => $message,
'priority-field' => $priority,
);
$this->assertEquals(
array($this->tableName, $binds),
$this->db->calls['insert'][0]
);
}
}


Expand Down

0 comments on commit 2882bc7

Please sign in to comment.