mirror of
https://github.com/doctrine/orm.git
synced 2026-03-26 07:52:11 +01:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f3bdab34c | ||
|
|
e075ab6958 | ||
|
|
3587f3bcb3 | ||
|
|
ec87cb779c | ||
|
|
ac40ce8042 | ||
|
|
d4302b32e1 | ||
|
|
3c95b0ec35 | ||
|
|
c12c6e82b6 | ||
|
|
505f7bd252 | ||
|
|
d5459616d2 | ||
|
|
97d9fb7efa | ||
|
|
2da1fadaf1 | ||
|
|
a612ca7231 | ||
|
|
bd4faa6a7d | ||
|
|
be03811753 | ||
|
|
636fa34136 | ||
|
|
016810af7f | ||
|
|
178fe38a39 |
@@ -325,9 +325,6 @@ class XmlDriver extends AbstractFileDriver
|
||||
$joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'});
|
||||
} else if (isset($manyToOneElement->{'join-columns'})) {
|
||||
foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
|
||||
if (!isset($joinColumnElement['name'])) {
|
||||
$joinColumnElement['name'] = $name;
|
||||
}
|
||||
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,6 +450,6 @@ class YamlDriver extends AbstractFileDriver
|
||||
*/
|
||||
protected function _loadMappingFile($file)
|
||||
{
|
||||
return \Symfony\Component\Yaml\Yaml::load($file);
|
||||
return \Symfony\Component\Yaml\Yaml::parse($file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ class ProxyFactory
|
||||
|
||||
$methods .= $parameterString . ')';
|
||||
$methods .= PHP_EOL . ' {' . PHP_EOL;
|
||||
$methods .= ' $this->_load();' . PHP_EOL;
|
||||
$methods .= ' $this->__load();' . PHP_EOL;
|
||||
$methods .= ' return parent::' . $method->getName() . '(' . $argumentString . ');';
|
||||
$methods .= PHP_EOL . ' }' . PHP_EOL;
|
||||
}
|
||||
@@ -269,7 +269,8 @@ class <proxyClassName> extends \<className> implements \Doctrine\ORM\Proxy\Proxy
|
||||
$this->_entityPersister = $entityPersister;
|
||||
$this->_identifier = $identifier;
|
||||
}
|
||||
private function _load()
|
||||
/** @private */
|
||||
public function __load()
|
||||
{
|
||||
if (!$this->__isInitialized__ && $this->_entityPersister) {
|
||||
$this->__isInitialized__ = true;
|
||||
@@ -279,7 +280,7 @@ class <proxyClassName> extends \<className> implements \Doctrine\ORM\Proxy\Proxy
|
||||
unset($this->_entityPersister, $this->_identifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
<methods>
|
||||
|
||||
public function __sleep()
|
||||
|
||||
@@ -137,8 +137,7 @@ EOT
|
||||
|
||||
$toType = strtolower($input->getArgument('to-type'));
|
||||
|
||||
$cme = new ClassMetadataExporter();
|
||||
$exporter = $cme->getExporter($toType, $destPath);
|
||||
$exporter = $this->getExporter($toType, $destPath);
|
||||
$exporter->setOverwriteExistingFiles( ($input->getOption('force') !== false) );
|
||||
|
||||
if ($toType == 'annotation') {
|
||||
@@ -167,4 +166,11 @@ EOT
|
||||
$output->write('No Metadata Classes to process.' . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getExporter($toType, $destPath)
|
||||
{
|
||||
$cme = new ClassMetadataExporter();
|
||||
|
||||
return $cme->getExporter($toType, $destPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,10 +70,10 @@ class ConvertDoctrine1Schema
|
||||
if (is_dir($path)) {
|
||||
$files = glob($path . '/*.yml');
|
||||
foreach ($files as $file) {
|
||||
$schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::load($file));
|
||||
$schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::parse($file));
|
||||
}
|
||||
} else {
|
||||
$schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::load($path));
|
||||
$schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::parse($path));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -741,7 +741,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$hasPostUpdateListeners = $this->evm->hasListeners(Events::postUpdate);
|
||||
|
||||
foreach ($this->entityUpdates as $oid => $entity) {
|
||||
if (get_class($entity) == $className || $entity instanceof Proxy && $entity instanceof $className) {
|
||||
if (get_class($entity) == $className || $entity instanceof Proxy && get_parent_class($entity) == $className) {
|
||||
|
||||
if ($hasPreUpdateLifecycleCallbacks) {
|
||||
$class->invokeLifecycleCallbacks(Events::preUpdate, $entity);
|
||||
@@ -781,7 +781,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$hasListeners = $this->evm->hasListeners(Events::postRemove);
|
||||
|
||||
foreach ($this->entityDeletions as $oid => $entity) {
|
||||
if (get_class($entity) == $className || $entity instanceof Proxy && $entity instanceof $className) {
|
||||
if (get_class($entity) == $className || $entity instanceof Proxy && get_parent_class($entity) == $className) {
|
||||
$persister->delete($entity);
|
||||
unset(
|
||||
$this->entityDeletions[$oid],
|
||||
@@ -1285,6 +1285,10 @@ class UnitOfWork implements PropertyChangedListener
|
||||
}
|
||||
|
||||
$visited[$oid] = $entity; // mark visited
|
||||
|
||||
// Cascade first, because scheduleForDelete() removes the entity from the identity map, which
|
||||
// can cause problems when a lazy proxy has to be initialized for the cascade operation.
|
||||
$this->cascadeRemove($entity, $visited);
|
||||
|
||||
$class = $this->em->getClassMetadata(get_class($entity));
|
||||
$entityState = $this->getEntityState($entity);
|
||||
@@ -1308,7 +1312,6 @@ class UnitOfWork implements PropertyChangedListener
|
||||
throw new UnexpectedValueException("Unexpected entity state: $entityState.");
|
||||
}
|
||||
|
||||
$this->cascadeRemove($entity, $visited);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1669,6 +1672,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if ( ! $assoc['isCascadePersist']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity);
|
||||
if (($relatedEntities instanceof Collection || is_array($relatedEntities))) {
|
||||
if ($relatedEntities instanceof PersistentCollection) {
|
||||
@@ -1697,7 +1701,11 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if ( ! $assoc['isCascadeRemove']) {
|
||||
continue;
|
||||
}
|
||||
//TODO: If $entity instanceof Proxy => Initialize ?
|
||||
|
||||
if ($entity instanceof Proxy && !$entity->__isInitialized__) {
|
||||
$entity->__load();
|
||||
}
|
||||
|
||||
$relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity);
|
||||
if ($relatedEntities instanceof Collection || is_array($relatedEntities)) {
|
||||
// If its a PersistentCollection initialization is intended! No unwrap!
|
||||
@@ -1848,8 +1856,8 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$idHash = $data[$class->identifier[0]];
|
||||
$id = array($class->identifier[0] => $idHash);
|
||||
}
|
||||
|
||||
if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
|
||||
|
||||
if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
|
||||
$entity = $this->identityMap[$class->rootEntityName][$idHash];
|
||||
$oid = spl_object_hash($entity);
|
||||
if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
|
||||
@@ -2260,7 +2268,28 @@ class UnitOfWork implements PropertyChangedListener
|
||||
{
|
||||
return $this->collectionUpdates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to initialize a lazy loading proxy or persistent collection.
|
||||
*
|
||||
* @param object
|
||||
* @return void
|
||||
*/
|
||||
public function initializeObject($obj)
|
||||
{
|
||||
if ($obj instanceof Proxy) {
|
||||
$obj->__load();
|
||||
} else if ($obj instanceof PersistentCollection) {
|
||||
$obj->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to show an object as string.
|
||||
*
|
||||
* @param object $obj
|
||||
* @return string
|
||||
*/
|
||||
private static function objToStr($obj)
|
||||
{
|
||||
return method_exists($obj, '__toString') ? (string)$obj : get_class($obj).'@'.spl_object_hash($obj);
|
||||
|
||||
@@ -36,7 +36,7 @@ class Version
|
||||
/**
|
||||
* Current Doctrine Version
|
||||
*/
|
||||
const VERSION = '2.0.5';
|
||||
const VERSION = '2.0.6';
|
||||
|
||||
/**
|
||||
* Compares a Doctrine version with the current one.
|
||||
|
||||
2
lib/vendor/Symfony/Component/Console
vendored
2
lib/vendor/Symfony/Component/Console
vendored
Submodule lib/vendor/Symfony/Component/Console updated: 4200b4bc95...3762cec59a
2
lib/vendor/Symfony/Component/Yaml
vendored
2
lib/vendor/Symfony/Component/Yaml
vendored
Submodule lib/vendor/Symfony/Component/Yaml updated: 3d864452ca...c3e1d03eff
2
lib/vendor/doctrine-dbal
vendored
2
lib/vendor/doctrine-dbal
vendored
Submodule lib/vendor/doctrine-dbal updated: 4ee7356ce0...abf4d00954
@@ -342,4 +342,19 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa
|
||||
$this->assertEquals('Developers_New1', $user->groups[0]->name);
|
||||
$this->assertEquals('Developers_New2', $user->groups[1]->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-733
|
||||
*/
|
||||
public function testInitializePersistentCollection()
|
||||
{
|
||||
$user = $this->addCmsUserGblancoWithGroups(2);
|
||||
$this->_em->clear();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
|
||||
$this->assertFalse($user->groups->isInitialized(), "Pre-condition: lazy collection");
|
||||
$this->_em->getUnitOfWork()->initializeObject($user->groups);
|
||||
$this->assertTrue($user->groups->isInitialized(), "Collection should be initialized after calling UnitOfWork::initializeObject()");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,4 +97,37 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertTrue($clone->isCloned);
|
||||
$this->assertFalse($entity->isCloned);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-733
|
||||
*/
|
||||
public function testInitializeProxy()
|
||||
{
|
||||
$id = $this->createProduct();
|
||||
|
||||
/* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
|
||||
$this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy.");
|
||||
$this->_em->getUnitOfWork()->initializeObject($entity);
|
||||
$this->assertTrue($entity->__isInitialized__, "Should be initialized after called UnitOfWork::initializeObject()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1163
|
||||
*/
|
||||
public function testInitializeChangeAndFlushProxy()
|
||||
{
|
||||
$id = $this->createProduct();
|
||||
|
||||
/* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
$entity->setName('Doctrine 2 Cookbook');
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
$this->assertEquals('Doctrine 2 Cookbook', $entity->getName());
|
||||
}
|
||||
}
|
||||
|
||||
215
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php
Normal file
215
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-1163
|
||||
*/
|
||||
class DDC1163Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163Product'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163SpecialProduct'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163ProxyHolder'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163Tag'),
|
||||
));
|
||||
}
|
||||
|
||||
public function testIssue()
|
||||
{
|
||||
$this->createSpecialProductAndProxyHolderReferencingIt();
|
||||
$this->_em->clear();
|
||||
|
||||
$this->createProxyForSpecialProduct();
|
||||
|
||||
$this->setPropertyAndAssignTagToSpecialProduct();
|
||||
|
||||
// fails
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
private function createSpecialProductAndProxyHolderReferencingIt()
|
||||
{
|
||||
$specialProduct = new DDC1163SpecialProduct();
|
||||
$this->_em->persist($specialProduct);
|
||||
|
||||
$proxyHolder = new DDC1163ProxyHolder();
|
||||
$this->_em->persist($proxyHolder);
|
||||
|
||||
$proxyHolder->setSpecialProduct($specialProduct);
|
||||
|
||||
$this->_em->flush();
|
||||
|
||||
$this->productId = $specialProduct->getId();
|
||||
$this->proxyHolderId = $proxyHolder->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* We want Doctrine to instantiate a lazy-load proxy for the previously created
|
||||
* 'SpecialProduct' and register it.
|
||||
*
|
||||
* When Doctrine loads the 'ProxyHolder', it will do just that because the 'ProxyHolder'
|
||||
* references the 'SpecialProduct'.
|
||||
*/
|
||||
private function createProxyForSpecialProduct()
|
||||
{
|
||||
/* @var $proxyHolder ProxyHolder */
|
||||
$proxyHolder = $this->_em->find(__NAMESPACE__ . '\\DDC1163ProxyHolder', $this->proxyHolderId);
|
||||
|
||||
$this->assertInstanceOf(__NAMESPACE__.'\\DDC1163SpecialProduct', $proxyHolder->getSpecialProduct());
|
||||
}
|
||||
|
||||
private function setPropertyAndAssignTagToSpecialProduct()
|
||||
{
|
||||
/* @var $specialProduct SpecialProduct */
|
||||
$specialProduct = $this->_em->find(__NAMESPACE__ . '\\DDC1163SpecialProduct', $this->productId);
|
||||
|
||||
$this->assertInstanceOf(__NAMESPACE__.'\\DDC1163SpecialProduct', $specialProduct);
|
||||
$this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $specialProduct);
|
||||
|
||||
$specialProduct->setSubclassProperty('foobar');
|
||||
|
||||
// this screams violation of law of demeter ;)
|
||||
$this->assertEquals(
|
||||
__NAMESPACE__.'\\DDC1163SpecialProduct',
|
||||
$this->_em->getUnitOfWork()->getEntityPersister(get_class($specialProduct))->getClassMetadata()->name
|
||||
);
|
||||
|
||||
$tag = new DDC1163Tag('Foo');
|
||||
$this->_em->persist($tag);
|
||||
$tag->setProduct($specialProduct);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1163ProxyHolder
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @Column(name="id", type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @var SpecialProduct
|
||||
* @OneToOne(targetEntity="DDC1163SpecialProduct")
|
||||
*/
|
||||
private $specialProduct;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setSpecialProduct(DDC1163SpecialProduct $specialProduct)
|
||||
{
|
||||
$this->specialProduct = $specialProduct;
|
||||
}
|
||||
|
||||
public function getSpecialProduct()
|
||||
{
|
||||
return $this->specialProduct;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorColumn(name="type", type="string")
|
||||
* @DiscriminatorMap({"special" = "DDC1163SpecialProduct"})
|
||||
*/
|
||||
abstract class DDC1163Product
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @Column(name="id", type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1163SpecialProduct extends DDC1163Product
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @Column(name="subclass_property", type="string", nullable=true)
|
||||
*/
|
||||
private $subclassProperty;
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setSubclassProperty($value)
|
||||
{
|
||||
$this->subclassProperty = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1163Tag
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @Column(name="id", type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @var string
|
||||
* @Column(name="name", type="string")
|
||||
*/
|
||||
private $name;
|
||||
/**
|
||||
* @var Product
|
||||
* @ManyToOne(targetEntity="DDC1163Product", inversedBy="tags")
|
||||
* @JoinColumns({
|
||||
* @JoinColumn(name="product_id", referencedColumnName="id")
|
||||
* })
|
||||
*/
|
||||
private $product;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
*/
|
||||
public function setProduct(DDC1163Product $product)
|
||||
{
|
||||
$this->product = $product;
|
||||
}
|
||||
|
||||
}
|
||||
93
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php
Normal file
93
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
use DateTime, Doctrine\DBAL\Types\Type;
|
||||
|
||||
class DDC1193Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Company'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Person'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Account')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1193
|
||||
*/
|
||||
public function testIssue()
|
||||
{
|
||||
$company = new DDC1193Company();
|
||||
$person = new DDC1193Person();
|
||||
$account = new DDC1193Account();
|
||||
|
||||
$person->account = $account;
|
||||
$person->company = $company;
|
||||
|
||||
$company->member = $person;
|
||||
|
||||
$this->_em->persist($company);
|
||||
|
||||
$this->_em->flush();
|
||||
|
||||
$companyId = $company->id;
|
||||
$accountId = $account->id;
|
||||
$this->_em->clear();
|
||||
|
||||
$company = $this->_em->find(get_class($company), $companyId);
|
||||
|
||||
$this->assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($company), "Company is in identity map.");
|
||||
$this->assertFalse($company->member->__isInitialized__, "Pre-Condition");
|
||||
$this->assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($company->member), "Member is in identity map.");
|
||||
|
||||
$this->_em->remove($company);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertEquals(count($this->_em->getRepository(get_class($account))->findAll()), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class DDC1193Company {
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/** @OneToOne(targetEntity="DDC1193Person", cascade={"persist", "remove"}) */
|
||||
public $member;
|
||||
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class DDC1193Person {
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @OneToOne(targetEntity="DDC1193Account", cascade={"persist", "remove"})
|
||||
*/
|
||||
public $account;
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class DDC1193Account {
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Performance;
|
||||
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Doctrine\ORM\Query;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class InheritancePersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('company');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testCompanyContract()
|
||||
{
|
||||
$person = new \Doctrine\Tests\Models\Company\CompanyEmployee();
|
||||
$person->setName('Poor Sales Guy');
|
||||
$person->setDepartment('Sales');
|
||||
$person->setSalary(100);
|
||||
$this->_em->persist($person);
|
||||
|
||||
for ($i = 0; $i < 33; $i++) {
|
||||
$fix = new \Doctrine\Tests\Models\Company\CompanyFixContract();
|
||||
$fix->setFixPrice(1000);
|
||||
$fix->setSalesPerson($person);
|
||||
$fix->markCompleted();
|
||||
$this->_em->persist($fix);
|
||||
|
||||
$flex = new \Doctrine\Tests\Models\Company\CompanyFlexContract();
|
||||
$flex->setSalesPerson($person);
|
||||
$flex->setHoursWorked(100);
|
||||
$flex->setPricePerHour(100);
|
||||
$flex->markCompleted();
|
||||
$this->_em->persist($flex);
|
||||
|
||||
$ultra = new \Doctrine\Tests\Models\Company\CompanyFlexUltraContract();
|
||||
$ultra->setSalesPerson($person);
|
||||
$ultra->setHoursWorked(150);
|
||||
$ultra->setPricePerHour(150);
|
||||
$ultra->setMaxPrice(7000);
|
||||
$this->_em->persist($ultra);
|
||||
}
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$start = microtime(true);
|
||||
$contracts = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyContract')->findAll();
|
||||
echo "99 CompanyContract: " . number_format(microtime(true) - $start, 6) . "\n";
|
||||
$this->assertEquals(99, count($contracts));
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$start = microtime(true);
|
||||
$contracts = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyContract')->findAll();
|
||||
echo "99 CompanyContract: " . number_format(microtime(true) - $start, 6) . "\n";
|
||||
$this->assertEquals(99, count($contracts));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Performance;
|
||||
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
|
||||
use Doctrine\Tests\Models\CMS\CmsAddress;
|
||||
use Doctrine\Tests\Models\CMS\CmsGroup;
|
||||
use Doctrine\Tests\Models\CMS\CmsArticle;
|
||||
use Doctrine\Tests\Models\CMS\CmsComment;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class PersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('cms');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testFindCmsArticle()
|
||||
{
|
||||
$author = new CmsUser();
|
||||
$author->name = "beberlei";
|
||||
$author->status = "active";
|
||||
$author->username = "beberlei";
|
||||
$this->_em->persist($author);
|
||||
|
||||
$ids = array();
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$article = new CmsArticle();
|
||||
$article->text = "foo";
|
||||
$article->topic = "bar";
|
||||
$article->user = $author;
|
||||
$this->_em->persist($article);
|
||||
$ids[] = $article;
|
||||
}
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$start = microtime(true);
|
||||
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->findAll();
|
||||
echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n";
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$start = microtime(true);
|
||||
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->findAll();
|
||||
echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n";
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$start = microtime(true);
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->find($ids[$i]->id);
|
||||
}
|
||||
echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n";
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$start = microtime(true);
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->find($ids[$i]->id);
|
||||
}
|
||||
echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n";
|
||||
}
|
||||
|
||||
public function testFindCmsGroup()
|
||||
{
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$group = new CmsGroup();
|
||||
$group->name = "foo" . $i;
|
||||
$this->_em->persist($group);
|
||||
}
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$start = microtime(true);
|
||||
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll();
|
||||
echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n";
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$start = microtime(true);
|
||||
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll();
|
||||
echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n";
|
||||
}
|
||||
|
||||
public function testFindCmsUser()
|
||||
{
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$user = new CmsUser();
|
||||
$user->name = "beberlei";
|
||||
$user->status = "active";
|
||||
$user->username = "beberlei".$i;
|
||||
$this->_em->persist($user);
|
||||
}
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$start = microtime(true);
|
||||
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll();
|
||||
echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n";
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$start = microtime(true);
|
||||
$articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll();
|
||||
echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user