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

Commit

Permalink
Browse files Browse the repository at this point in the history
- Incorporate feedback from issue comments
- Ensure CS is followed
- Added assertions to testPassingTableNameAsArgIsOK()
- Simplified messages in expected exception matching in new tests
  • Loading branch information
weierophinney committed Aug 21, 2012
1 parent e00fd2b commit 492076c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
11 changes: 4 additions & 7 deletions src/Writer/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,15 @@ public function __construct($db, $tableName = null, array $columnMap = null, $se
$db = isset($db['db']) ? $db['db'] : null;
}

if (null === $db){
throw new Exception\InvalidArgumentException('You must specify a database adapter either explicitly in the constructor or in options array with key "db"');
if (!$db instanceof Adapter) {
throw new Exception\InvalidArgumentException('You must pass a valid Zend\Db\Adapter\Adapter');
}

if (null === $tableName){
$tableName = (string) $tableName;
if ('' === $tableName){
throw new Exception\InvalidArgumentException('You must specify a table name. Either directly in the constructor, or via options');
}

if (!$db instanceof Adapter) {
throw new Exception\InvalidArgumentException('You must pass a valid Zend\Db\Adapter\Adapter');
}

$this->db = $db;
$this->tableName = $tableName;
$this->columnMap = $columnMap;
Expand Down
23 changes: 14 additions & 9 deletions test/Writer/DbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,27 @@ public function testFormattingIsNotSupported()
$this->writer->setFormatter(new SimpleFormatter);
}

public function testNotPassingTableNameToConstructorThrowsException(){
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'You must specify a table name. Either directly in the constructor, or via options');
new DbWriter($this->db);
public function testNotPassingTableNameToConstructorThrowsException()
{
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'table name');
$writer = new DbWriter($this->db);
}

public function testNotPassingDbToConstructorThrowsException(){
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'You must specify a database adapter either explicitly in the constructor or in options array with key "db"');
new DbWriter(array());
public function testNotPassingDbToConstructorThrowsException()
{
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Adapter');
$writer = new DbWriter(array());
}

public function testPassingTableNameAsArgIsOK(){
public function testPassingTableNameAsArgIsOK()
{
$options = array(
'db' => $this->db,
'db' => $this->db,
'table' => $this->tableName,
);
new DbWriter ($options);
$writer = new DbWriter($options);
$this->assertInstanceOf('Zend\Log\Writer\Db', $writer);
$this->assertAttributeEquals($this->tableName, 'tableName', $writer);
}

public function testWriteWithDefaults()
Expand Down

0 comments on commit 492076c

Please sign in to comment.