Created
December 20, 2013 16:00
-
-
Save McManning/8056822 to your computer and use it in GitHub Desktop.
Propel issue with improperly creating additional objects and improperly setting references when performing deep copies of one-to-one relationships.
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
<?php | |
require_once dirname(__FILE__) . '/../../tools/helpers/bookstore/BookstoreTestBase.php'; | |
/** | |
* Tests for replicating one-to-one relations while performing a deep copy. | |
* | |
* @author Chase McManning | |
* @version $Revision$ | |
* @package misc | |
*/ | |
class DeepCopyReplicationTest extends BookstoreTestBase | |
{ | |
protected function setUp() | |
{ | |
parent::setUp(); | |
BookstoreEmployeePeer::doDeleteAll(); | |
BookstoreEmployeeAccountPeer::doDeleteAll(); | |
} | |
/** | |
* Simple variation | |
*/ | |
public function testDeepCopyOneToOneSimple() | |
{ | |
$a = new BookstoreEmployee(); | |
$a->setName('Joe'); | |
$a->setJobTitle('Event Organizer'); | |
$aAcc = new BookstoreEmployeeAccount(); | |
$aAcc->setBookstoreEmployee($a); | |
$aAcc->setPassword('mysecret'); | |
$a->save(); | |
$b = $a->copy(true); | |
$b->setName('Joe Copy'); | |
$b->save(); | |
$bAcc = BookstoreEmployeeAccountQuery::create()->findOneByBookstoreEmployee($b); | |
$count = BookstoreEmployeeQuery::create()->count(); | |
$countAcc = BookstoreEmployeeAccountQuery::create()->count(); | |
$this->assertEquals(2, $count, 'Single replication of BookstoreEmployee account row must be created'); | |
$this->assertEquals(2, $countAcc, 'Single replication of BookstoreEmployeeAccount row must be created'); | |
$this->assertTrue($bAcc instanceof BookstoreEmployeeAccount, 'Cloned account returns a one-to-one relationship with employee'); | |
$this->assertEquals($b->getBookstoreEmployeeAccount(), $bAcc, 'Cloned employee references cloned account'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment