This repository was archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Fix and test case for: RowGateway primary key not null constraint do not fail with empty string #6335
Merged
weierophinney
merged 6 commits into
zendframework:master
from
jeanCarloMachado:fix-row-gateway
Aug 7, 2014
Merged
Fix and test case for: RowGateway primary key not null constraint do not fail with empty string #6335
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7879dd5
teste jean
fc8e262
Merge branch 'master' of https://github.com/zendframework/zf2
4653700
Merge branch 'master' of https://github.com/zendframework/zf2
2e9d524
bug fix and respective test case for empty string on RowAbstract cons…
7118d5c
removed system automatically created files
1f53530
removed self created php info
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| 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)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EOF EOL |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= nullis not needed. Missing docblocks