Skip to content

Instantly share code, notes, and snippets.

@McManning
Created December 20, 2013 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McManning/8056822 to your computer and use it in GitHub Desktop.
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.
<?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