From 492076c1abb7e3d1af657f253f5f808fa71c234c Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 21 Aug 2012 10:35:40 -0500 Subject: [PATCH] [zendframework/zf2#2209] CS review - Incorporate feedback from issue comments - Ensure CS is followed - Added assertions to testPassingTableNameAsArgIsOK() - Simplified messages in expected exception matching in new tests --- src/Writer/Db.php | 11 ++++------- test/Writer/DbTest.php | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Writer/Db.php b/src/Writer/Db.php index 207df2ee..7f0eba9e 100644 --- a/src/Writer/Db.php +++ b/src/Writer/Db.php @@ -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; diff --git a/test/Writer/DbTest.php b/test/Writer/DbTest.php index 6bc43513..f20717ce 100644 --- a/test/Writer/DbTest.php +++ b/test/Writer/DbTest.php @@ -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()