forked from propelorm/Propel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clone object in hashCode() function so the original object is not cha…
…nged when calling hashCode provided test for the hasCode() function
- Loading branch information
Daniel Tschinder
committed
May 3, 2013
1 parent
3ea2f2d
commit 0272ba3
Showing
2 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,100 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Propel package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
require_once dirname(__FILE__) . '/../../../tools/helpers/bookstore/BookstoreTestBase.php'; | ||
|
||
/** | ||
* Test class for BaseObject serialization. | ||
* | ||
* @author Francois Zaninotto | ||
* @version $Id: PropelCollectionTest.php 1348 2009-12-03 21:49:00Z francois $ | ||
* @package runtime.om | ||
* @group hashcode | ||
*/ | ||
class BaseObjectHashCodeTest extends BookstoreTestBase | ||
{ | ||
public function testUnsavedObjectCallingHashCodeIsNotChangingObject() | ||
{ | ||
$book1 = new Book(); | ||
$book1->setTitle('Foo5'); | ||
$book1->setISBN('1234'); | ||
|
||
$author = new Author(); | ||
$author->setFirstName('JAne'); | ||
$author->setLastName('JAne'); | ||
$author->addBook($book1); | ||
|
||
$a = clone $author; | ||
$a->hashCode(); | ||
|
||
$this->assertEquals($a, $author); | ||
} | ||
|
||
public function testSavedObjectCallingHashCodeIsNotChangingObject() | ||
{ | ||
$book1 = new Book(); | ||
$book1->setTitle('Foo5'); | ||
$book1->setISBN('1234'); | ||
|
||
$author = new Author(); | ||
$author->setFirstName('JAne'); | ||
$author->setLastName('JAne'); | ||
$author->addBook($book1); | ||
$author->save(); | ||
|
||
$a = clone $author; | ||
$a->hashCode(); | ||
|
||
$this->assertEquals($a, $author); | ||
} | ||
|
||
public function testUnsavedObjectCreatesSameHashForIdenticalObjects() | ||
{ | ||
$book1 = new Book(); | ||
$book1->setTitle('Foo5'); | ||
$book1->setISBN('1234'); | ||
|
||
$author1 = new Author(); | ||
$author1->setFirstName('JAne'); | ||
$author1->setLastName('JAne'); | ||
$author1->addBook($book1); | ||
|
||
$author2 = new Author(); | ||
$author2->setFirstName('JAne'); | ||
$author2->setLastName('JAne'); | ||
$author2->addBook($book1); | ||
|
||
$this->assertEquals($author1->hashCode(), $author2->hashCode()); | ||
} | ||
|
||
/** | ||
* Primary key should differ | ||
*/ | ||
public function testSavedObjectCreatesDifferentHashForIdenticalObjects() | ||
{ | ||
$book1 = new Book(); | ||
$book1->setTitle('Foo5'); | ||
$book1->setISBN('1234'); | ||
|
||
$author1 = new Author(); | ||
$author1->setFirstName('JAne'); | ||
$author1->setLastName('JAne'); | ||
$author1->addBook($book1); | ||
$author1->save(); | ||
|
||
$author2 = new Author(); | ||
$author2->setFirstName('JAne'); | ||
$author2->setLastName('JAne'); | ||
$author2->addBook($book1); | ||
$author2->save(); | ||
|
||
$this->assertNotEquals($author1->hashCode(), $author2->hashCode()); | ||
} | ||
} |