Permalink
Browse files

Port #3988 to develop

Merge branch 'Mech7-unit-test-preparestatement' into develop
  • Loading branch information...
2 parents b50c0bd + 9213016 commit b2eda39152910894409d5b6fabf0e854d5bfb7a1 @ralphschindler ralphschindler committed Mar 13, 2013
Showing with 21 additions and 2 deletions.
  1. +6 −2 library/Zend/Db/Sql/Insert.php
  2. +15 −0 tests/ZendTest/Db/Sql/SqlTest.php
@@ -168,13 +168,17 @@ public function prepareStatement(AdapterInterface $adapter, StatementContainerIn
foreach ($this->columns as $cIndex => $column) {
$columns[$cIndex] = $platform->quoteIdentifier($column);
- if ($this->values[$cIndex] instanceof Expression) {
+ if (isset($this->values[$cIndex]) && $this->values[$cIndex] instanceof Expression) {
$exprData = $this->processExpression($this->values[$cIndex], $platform, $driver);
$values[$cIndex] = $exprData->getSql();
$parameterContainer->merge($exprData->getParameterContainer());
} else {
$values[$cIndex] = $driver->formatParameterName($column);
- $parameterContainer->offsetSet($column, $this->values[$cIndex]);
+ if (isset($this->values[$cIndex])) {
+ $parameterContainer->offsetSet($column, $this->values[$cIndex]);
+ } else {
+ $parameterContainer->offsetSet($column, null);
+ }
}
}
@@ -16,6 +16,11 @@ class TableGatewayTest extends \PHPUnit_Framework_TestCase
{
protected $mockAdapter = null;
+
+ /**
+ * Sql object
+ * @var Sql
+ */
protected $sql = null;
public function setup()
@@ -110,4 +115,14 @@ public function testDelete()
$this->sql->delete('bar');
}
+
+ /**
+ * @covers Zend\Db\Sql\Sql::prepareStatementForSqlObject
+ */
+ public function testPrepareStatementForSqlObject()
+ {
+ $insert = $this->sql->insert()->columns(array('foo'));
+ $stmt = $this->sql->prepareStatementForSqlObject($insert);
+ $this->assertInstanceOf('Zend\Db\Adapter\Driver\StatementInterface', $stmt);
+ }
}

0 comments on commit b2eda39

Please sign in to comment.