Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/Zend/Db/RowGateway/RowGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
59 changes: 59 additions & 0 deletions tests/ZendTest/Db/RowGateway/RowGatewayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Db\RowGateway;

use Zend\Db\RowGateway\RowGateway;

class RowGatewayTest extends \PHPUnit_Framework_TestCase
{

protected $mockAdapter = null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= null is not needed. Missing docblocks


protected $rowGateway = null;

public function setup()
{
// mock the adapter, driver, and parts
$mockResult = $this->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));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split mocking logic from instantiation into separate blocks: makes it much more readable

$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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably expect an exception instead of using try-catch.

$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);
}
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOF EOL