diff --git a/library/Zend/Db/RowGateway/RowGateway.php b/library/Zend/Db/RowGateway/RowGateway.php index 1415d6995e7..d77786adaa3 100644 --- a/library/Zend/Db/RowGateway/RowGateway.php +++ b/library/Zend/Db/RowGateway/RowGateway.php @@ -25,8 +25,9 @@ class RowGateway extends AbstractRowGateway */ public function __construct($primaryKeyColumn, $table, $adapterOrSql = null) { + // setup primary key - $this->primaryKeyColumn = (array) $primaryKeyColumn; + $this->primaryKeyColumn = empty($primaryKeyColumn) ? null : (array) $primaryKeyColumn; // set table $this->table = $table; diff --git a/tests/ZendTest/Db/RowGateway/RowGatewayTest.php b/tests/ZendTest/Db/RowGateway/RowGatewayTest.php new file mode 100644 index 00000000000..1ee7fae097e --- /dev/null +++ b/tests/ZendTest/Db/RowGateway/RowGatewayTest.php @@ -0,0 +1,59 @@ +getMock('Zend\Db\Adapter\Driver\ResultInterface'); + $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(1)); + $this->mockResult = $mockResult; + $mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface'); + $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult)); + $mockConnection = $this->getMock('Zend\Db\Adapter\Driver\ConnectionInterface'); + $mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface'); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); + $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); + + // setup mock adapter + $this->mockAdapter = $this->getMock('Zend\Db\Adapter\Adapter', null, array($mockDriver)); + } + + public function testEmptyPrimaryKey() + { + try { + $this->rowGateway = new \Zend\Db\RowGateway\RowGateway('', 'foo', $this->mockAdapter); + + $this->fail('Excepcted null primary key exception not thrown'); + } catch (\Zend\Db\RowGateway\Exception\RuntimeException $e) { + $this->assertEquals($e->getMessage(), 'This row object does not have a primary key column set.'); + } + } + + + protected function setRowGatewayState(array $properties) + { + $refRowGateway = new \ReflectionObject($this->rowGateway); + foreach ($properties as $rgPropertyName => $rgPropertyValue) { + $refRowGatewayProp = $refRowGateway->getProperty($rgPropertyName); + $refRowGatewayProp->setAccessible(true); + $refRowGatewayProp->setValue($this->rowGateway, $rgPropertyValue); + } + } +} \ No newline at end of file