mirror of
https://github.com/doctrine/orm.git
synced 2026-04-26 07:58:09 +02:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bc4ddbfb01 | |||
| 14499f5021 | |||
| aae43cbb77 | |||
| db6cb8dedc | |||
| 5092da074a | |||
| 1c6524db55 | |||
| d9fc5388f1 | |||
| d2e51eacff | |||
| 5a6ae4686f | |||
| 8b8a1cbe81 | |||
| 27a5284899 | |||
| 0086d17afe | |||
| ab62167c8a | |||
| 6d43195669 | |||
| 7065ff0ac9 | |||
| aa61328e90 | |||
| 62719f2a97 | |||
| 66770c5bfe | |||
| 42691c21b4 | |||
| 596e895763 | |||
| d5c82094df | |||
| 4148220f9c | |||
| e173c930ec | |||
| 7071984559 | |||
| 216c466233 | |||
| 65f5777e60 | |||
| 6e3ce26429 | |||
| 752d4f9eac | |||
| 2983081a60 |
@@ -23,9 +23,6 @@ script:
|
||||
- ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS
|
||||
- ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls -v
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
- php: hhvm
|
||||
|
||||
+2
-3
@@ -18,14 +18,13 @@
|
||||
"doctrine/collections": "~1.2",
|
||||
"doctrine/dbal": ">=2.5-dev,<2.6-dev",
|
||||
"doctrine/instantiator": "~1.0.1",
|
||||
"doctrine/common": ">=2.5-dev,<2.6-dev",
|
||||
"doctrine/common": ">=2.5-dev,<2.7-dev",
|
||||
"doctrine/cache": "~1.4",
|
||||
"symfony/console": "~2.5|~3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/yaml": "~2.3|~3.0",
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"satooshi/php-coveralls": "dev-master"
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/yaml": "If you want to use YAML Metadata Mapping Driver"
|
||||
|
||||
@@ -73,7 +73,7 @@ class DefaultEntityHydrator implements EntityHydrator
|
||||
public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $entity)
|
||||
{
|
||||
$data = $this->uow->getOriginalEntityData($entity);
|
||||
$data = array_merge($data, $key->identifier); // why update has no identifier values ?
|
||||
$data = array_merge($data, $metadata->getIdentifierValues($entity)); // why update has no identifier values ?
|
||||
|
||||
foreach ($metadata->associationMappings as $name => $assoc) {
|
||||
|
||||
|
||||
@@ -965,7 +965,7 @@ class Parser
|
||||
$schemaName = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
|
||||
}
|
||||
|
||||
$exists = class_exists($schemaName, true);
|
||||
$exists = class_exists($schemaName, true) || interface_exists($schemaName, true);
|
||||
|
||||
if ( ! $exists) {
|
||||
$this->semanticalError("Class '$schemaName' is not defined.", $this->lexer->token);
|
||||
|
||||
@@ -1870,7 +1870,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
}
|
||||
}
|
||||
|
||||
if ($class->isVersioned) {
|
||||
if ($class->isVersioned && $this->isLoaded($managedCopy) && $this->isLoaded($entity)) {
|
||||
$reflField = $class->reflFields[$class->versionField];
|
||||
$managedCopyVersion = $reflField->getValue($managedCopy);
|
||||
$entityVersion = $reflField->getValue($entity);
|
||||
@@ -1883,7 +1883,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$visited[$oid] = $managedCopy; // mark visited
|
||||
|
||||
if (!($entity instanceof Proxy && ! $entity->__isInitialized())) {
|
||||
if ($this->isLoaded($entity)) {
|
||||
if ($managedCopy instanceof Proxy && ! $managedCopy->__isInitialized()) {
|
||||
$managedCopy->__load();
|
||||
}
|
||||
@@ -1908,6 +1908,18 @@ class UnitOfWork implements PropertyChangedListener
|
||||
return $managedCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if an entity is loaded - must either be a loaded proxy or not a proxy
|
||||
*
|
||||
* @param object $entity
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isLoaded($entity)
|
||||
{
|
||||
return !($entity instanceof Proxy) || $entity->__isInitialized();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets/adds associated managed copies into the previous entity's association field
|
||||
*
|
||||
|
||||
@@ -36,7 +36,7 @@ class Version
|
||||
/**
|
||||
* Current Doctrine Version
|
||||
*/
|
||||
const VERSION = '2.5.2';
|
||||
const VERSION = '2.5.4';
|
||||
|
||||
/**
|
||||
* Compares a Doctrine version with the current one.
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\VersionedManyToOne;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="versioned_many_to_one_article")
|
||||
*/
|
||||
class Article
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @Column(name="id", type="integer")
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @Column(name="name")
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="Category", cascade={"merge", "persist"})
|
||||
*/
|
||||
public $category;
|
||||
|
||||
/**
|
||||
* Version column
|
||||
*
|
||||
* @Column(type="integer", name="version")
|
||||
* @Version
|
||||
*/
|
||||
public $version;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\VersionedManyToOne;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="versioned_many_to_one_category")
|
||||
*/
|
||||
class Category
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @Column(name="id", type="integer")
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* Version column
|
||||
*
|
||||
* @Column(type="integer", name="version")
|
||||
* @Version
|
||||
*/
|
||||
public $version;
|
||||
}
|
||||
@@ -119,7 +119,7 @@ class DefaultEntityHydratorTest extends OrmTestCase
|
||||
$this->assertArrayHasKey('name', $cache->data);
|
||||
$this->assertArrayHasKey('country', $cache->data);
|
||||
$this->assertEquals(array(
|
||||
'id' => 11,
|
||||
'id' => 12,
|
||||
'name' => 'Bar',
|
||||
'country' => new AssociationCacheEntry(Country::CLASSNAME, array('id' => 11)),
|
||||
), $cache->data);
|
||||
@@ -147,9 +147,39 @@ class DefaultEntityHydratorTest extends OrmTestCase
|
||||
$this->assertArrayHasKey('name', $cache->data);
|
||||
$this->assertArrayHasKey('country', $cache->data);
|
||||
$this->assertEquals(array(
|
||||
'id' => 11,
|
||||
'id' => 12,
|
||||
'name' => 'Bar',
|
||||
'country' => new AssociationCacheEntry(Country::CLASSNAME, array('id' => 11)),
|
||||
), $cache->data);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCacheEntryWithWrongIdentifierType()
|
||||
{
|
||||
$proxy = $this->em->getReference(Country::CLASSNAME, 11);
|
||||
$entity = new State('Bat', $proxy);
|
||||
$uow = $this->em->getUnitOfWork();
|
||||
$entityData = array('id'=> 12, 'name'=>'Bar', 'country' => $proxy);
|
||||
$metadata = $this->em->getClassMetadata(State::CLASSNAME);
|
||||
$key = new EntityCacheKey($metadata->name, array('id'=>'12'));
|
||||
|
||||
$entity->setId(12);
|
||||
|
||||
$uow->registerManaged($entity, array('id'=>12), $entityData);
|
||||
|
||||
$cache = $this->structure->buildCacheEntry($metadata, $key, $entity);
|
||||
|
||||
$this->assertInstanceOf('Doctrine\ORM\Cache\CacheEntry', $cache);
|
||||
$this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheEntry', $cache);
|
||||
|
||||
$this->assertArrayHasKey('id', $cache->data);
|
||||
$this->assertArrayHasKey('name', $cache->data);
|
||||
$this->assertArrayHasKey('country', $cache->data);
|
||||
$this->assertSame($entity->getId(), $cache->data['id']);
|
||||
$this->assertEquals(array(
|
||||
'id' => 12,
|
||||
'name' => 'Bar',
|
||||
'country' => new AssociationCacheEntry(Country::CLASSNAME, array('id' => 11)),
|
||||
), $cache->data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\OptimisticLockException;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Doctrine\Tests\Models\VersionedManyToOne\Article;
|
||||
use Doctrine\Tests\Models\VersionedManyToOne\Category;
|
||||
|
||||
/**
|
||||
* @group MergeVersionedOneToMany
|
||||
*/
|
||||
class MergeVersionedManyToOneTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('versioned_many_to_one');
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test case asserts that a detached and unmodified entity could be merge without firing
|
||||
* OptimisticLockException.
|
||||
*/
|
||||
public function testSetVersionOnCreate()
|
||||
{
|
||||
$category = new Category();
|
||||
$article = new Article();
|
||||
|
||||
$article->name = 'Article';
|
||||
$article->category = $category;
|
||||
|
||||
$this->_em->persist($article);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$articleMerged = $this->_em->merge($article);
|
||||
|
||||
$articleMerged->name = 'Article Merged';
|
||||
|
||||
$this->_em->flush();
|
||||
$this->assertEquals(2, $articleMerged->version);
|
||||
}
|
||||
}
|
||||
@@ -105,16 +105,16 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
|
||||
|
||||
$cache = new \Doctrine\Common\Cache\ArrayCache();
|
||||
$cache = $this->getMock('Doctrine\Common\Cache\Cache');
|
||||
|
||||
$query->setQueryCacheDriver($cache);
|
||||
|
||||
$users = $query->getResult();
|
||||
$cache
|
||||
->expects(self::once())
|
||||
->method('save')
|
||||
->with(self::isType('string'), self::isInstanceOf('Doctrine\ORM\Query\ParserResult'));
|
||||
|
||||
$data = $this->cacheDataReflection->getValue($cache);
|
||||
$this->assertEquals(1, count($data));
|
||||
|
||||
$this->assertInstanceOf('Doctrine\ORM\Query\ParserResult', array_pop($data));
|
||||
$query->getResult();
|
||||
}
|
||||
|
||||
public function testQueryCache_HitDoesNotSaveParserResult()
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Tests\Models\Cache\Country;
|
||||
use Doctrine\Tests\ORM\Functional\SecondLevelCacheAbstractTest;
|
||||
|
||||
class DDC3967Test extends SecondLevelCacheAbstractTest
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->loadFixturesCountries();
|
||||
$this->_em->getCache()->evictEntityRegion(Country::CLASSNAME);
|
||||
$this->_em->clear();
|
||||
}
|
||||
|
||||
public function testIdentifierCachedWithProperType()
|
||||
{
|
||||
$country = array_pop($this->countries);
|
||||
$id = $country->getId();
|
||||
|
||||
// First time, loaded from database
|
||||
$this->_em->find(Country::CLASSNAME, "$id");
|
||||
$this->_em->clear();
|
||||
|
||||
// Second time, loaded from cache
|
||||
/** @var Country $country */
|
||||
$country = $this->_em->find(Country::CLASSNAME, "$id");
|
||||
|
||||
// Identifier type should be integer
|
||||
$this->assertSame($country->getId(), $id);
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->setExpectedException(
|
||||
'Doctrine\Common\Persistence\Mapping\MappingException',
|
||||
"No mapping file found named '".$this->dir."/Foo".$this->getFileExtension()."' for class 'MyNamespace\MySubnamespace\Entity\Foo'."
|
||||
"No mapping file found named"
|
||||
);
|
||||
|
||||
$driver = $this->getDriver(array(
|
||||
|
||||
@@ -85,6 +85,6 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
|
||||
))
|
||||
);
|
||||
|
||||
$this->assertStringMatchesFormat('string%sSELECT %a', $this->tester->getDisplay());
|
||||
$this->assertStringMatchesFormat('%Astring%sSELECT %a', $this->tester->getDisplay());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,19 +9,19 @@ use Doctrine\ORM\Events;
|
||||
class ResolveTargetEntityListenerTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
* @var \Doctrine\ORM\EntityManager
|
||||
*/
|
||||
private $em = null;
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var ResolveTargetEntityListener
|
||||
*/
|
||||
private $listener = null;
|
||||
private $listener;
|
||||
|
||||
/**
|
||||
* @var ClassMetadataFactory
|
||||
*/
|
||||
private $factory = null;
|
||||
private $factory;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -106,6 +106,32 @@ class ResolveTargetEntityListenerTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['targetEntity']);
|
||||
$this->assertEquals(array('resolvetargetentity_id', 'targetinterface_id'), $meta['joinTableColumns']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 1572
|
||||
* @group functional
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testDoesResolveTargetEntitiesInDQLAlsoWithInterfaces()
|
||||
{
|
||||
$evm = $this->em->getEventManager();
|
||||
$this->listener->addResolveTargetEntity(
|
||||
'Doctrine\Tests\ORM\Tools\ResolveTargetInterface',
|
||||
'Doctrine\Tests\ORM\Tools\ResolveTargetEntity',
|
||||
array()
|
||||
);
|
||||
|
||||
$evm->addEventSubscriber($this->listener);
|
||||
|
||||
$this->assertStringMatchesFormat(
|
||||
'SELECT%AFROM ResolveTargetEntity%A',
|
||||
$this
|
||||
->em
|
||||
->createQuery('SELECT f FROM Doctrine\Tests\ORM\Tools\ResolveTargetInterface f')
|
||||
->getSQL()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
interface ResolveTargetInterface
|
||||
|
||||
@@ -280,6 +280,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
'Doctrine\Tests\Models\Pagination\User',
|
||||
'Doctrine\Tests\Models\Pagination\User1',
|
||||
),
|
||||
'versioned_many_to_one' => array(
|
||||
'Doctrine\Tests\Models\VersionedManyToOne\Category',
|
||||
'Doctrine\Tests\Models\VersionedManyToOne\Article',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -535,6 +539,11 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
$conn->executeUpdate('DELETE FROM pagination_user');
|
||||
}
|
||||
|
||||
if (isset($this->_usedModelSets['versioned_many_to_one'])) {
|
||||
$conn->executeUpdate('DELETE FROM versioned_many_to_one_article');
|
||||
$conn->executeUpdate('DELETE FROM versioned_many_to_one_category');
|
||||
}
|
||||
|
||||
$this->_em->clear();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user