mirror of
https://github.com/doctrine/orm.git
synced 2026-04-01 20:02:15 +02:00
Compare commits
63 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3aa3f2d1d | ||
|
|
c83f479633 | ||
|
|
741f1db198 | ||
|
|
22546a3811 | ||
|
|
efa058bd8f | ||
|
|
767577cec6 | ||
|
|
c0f593e422 | ||
|
|
d89d238594 | ||
|
|
2337b7aedd | ||
|
|
9e6f061bfb | ||
|
|
bf1188127e | ||
|
|
c73ec2aa76 | ||
|
|
095611c4b6 | ||
|
|
96c6f4cf1d | ||
|
|
5cacb6e14f | ||
|
|
ab63628960 | ||
|
|
15731c7bde | ||
|
|
abb429a0c9 | ||
|
|
61cb03bf30 | ||
|
|
d6bcb5b1f8 | ||
|
|
bdae362777 | ||
|
|
59c5574554 | ||
|
|
9545bf9d8c | ||
|
|
5521d1f325 | ||
|
|
49694dc335 | ||
|
|
3155d970d3 | ||
|
|
09189fc021 | ||
|
|
5a0d3e5fb8 | ||
|
|
b9ba4e3207 | ||
|
|
d7919678e5 | ||
|
|
8b185eb822 | ||
|
|
693a0546d3 | ||
|
|
5c5c8fc487 | ||
|
|
85dc707cc8 | ||
|
|
64a1251b61 | ||
|
|
65ed6a2c2f | ||
|
|
d27a9fce7a | ||
|
|
11659f5cfe | ||
|
|
68dad26482 | ||
|
|
b3ceef0fb6 | ||
|
|
095b365146 | ||
|
|
7c1ebd99bc | ||
|
|
c06f19db8d | ||
|
|
0be9be4e24 | ||
|
|
b2bf5ee92e | ||
|
|
698bd813a2 | ||
|
|
b2ac8fdfd7 | ||
|
|
9c2b54b748 | ||
|
|
910784213f | ||
|
|
1d1de7de80 | ||
|
|
741da6eed7 | ||
|
|
ad5397b581 | ||
|
|
57bb46ca9d | ||
|
|
0416d5e036 | ||
|
|
a14432117a | ||
|
|
824f62d3bb | ||
|
|
c0f0fe060f | ||
|
|
caffbe04a2 | ||
|
|
d2c805b071 | ||
|
|
04fc7a9a1c | ||
|
|
149b8f4e09 | ||
|
|
48e8c02cb8 | ||
|
|
e218866a69 |
19
.travis.yml
19
.travis.yml
@@ -5,8 +5,6 @@ php:
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
- hhvm-nightly
|
||||
|
||||
env:
|
||||
- DB=mysql
|
||||
@@ -15,7 +13,7 @@ env:
|
||||
|
||||
before_script:
|
||||
- if [[ $TRAVIS_PHP_VERSION = '5.6' && $DB = 'sqlite' ]]; then PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else PHPUNIT_FLAGS=""; fi
|
||||
- if [[ $TRAVIS_PHP_VERSION != '5.6' && $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != 'hhvm-nightly' && $TRAVIS_PHP_VERSION != '7.0' ]]; then phpenv config-rm xdebug.ini; fi
|
||||
- if [[ $PHPUNIT_FLAGS == "" ]]; then phpenv config-rm xdebug.ini; fi
|
||||
- composer self-update
|
||||
- composer install --prefer-source --dev
|
||||
|
||||
@@ -24,15 +22,10 @@ script:
|
||||
- ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
- php: hhvm
|
||||
env: DB=pgsql # driver currently unsupported by HHVM
|
||||
- php: hhvm
|
||||
env: DB=mysqli # driver currently unsupported by HHVM
|
||||
- php: hhvm-nightly
|
||||
env: DB=pgsql # driver currently unsupported by HHVM
|
||||
- php: hhvm-nightly
|
||||
env: DB=mysqli # driver currently unsupported by HHVM
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- php: 7.0
|
||||
- php: hhvm-nightly # hhvm-nightly currently chokes on composer installation
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
"php": ">=5.4",
|
||||
"ext-pdo": "*",
|
||||
"doctrine/collections": "~1.2",
|
||||
"doctrine/dbal": ">=2.5-dev,<2.6-dev",
|
||||
"doctrine/dbal": ">=2.5-dev,<2.7-dev",
|
||||
"doctrine/instantiator": "~1.0.1",
|
||||
"doctrine/common": ">=2.5-dev,<2.8-dev",
|
||||
"doctrine/common": ">=2.5-dev,<2.9-dev",
|
||||
"doctrine/cache": "~1.4",
|
||||
"symfony/console": "~2.5|~3.0"
|
||||
},
|
||||
|
||||
@@ -30,7 +30,7 @@ use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs as BaseLoadClas
|
||||
* Note: method annotations are used instead of method overrides (due to BC policy)
|
||||
*
|
||||
* @method __construct(\Doctrine\ORM\Mapping\ClassMetadata $classMetadata, \Doctrine\ORM\EntityManager $objectManager)
|
||||
* @method \Doctrine\ORM\EntityManager getClassMetadata()
|
||||
* @method \Doctrine\ORM\Mapping\ClassMetadata getClassMetadata()
|
||||
*/
|
||||
class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs
|
||||
{
|
||||
|
||||
@@ -210,6 +210,9 @@ abstract class AbstractHydrator
|
||||
$this->_rsm = null;
|
||||
$this->_cache = array();
|
||||
$this->_metadataCache = array();
|
||||
|
||||
$evm = $this->_em->getEventManager();
|
||||
$evm->removeEventListener(array(Events::onClear), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -360,8 +360,8 @@ class ObjectHydrator extends AbstractHydrator
|
||||
|
||||
// Get a reference to the parent object to which the joined element belongs.
|
||||
if ($this->_rsm->isMixed && isset($this->rootAliases[$parentAlias])) {
|
||||
$first = reset($this->resultPointers);
|
||||
$parentObject = $first[key($first)];
|
||||
$objectClass = $this->resultPointers[$parentAlias];
|
||||
$parentObject = $objectClass[key($objectClass)];
|
||||
} else if (isset($this->resultPointers[$parentAlias])) {
|
||||
$parentObject = $this->resultPointers[$parentAlias];
|
||||
} else {
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
namespace Doctrine\ORM;
|
||||
|
||||
use Closure;
|
||||
use Doctrine\Common\Collections\AbstractLazyCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
@@ -375,11 +374,7 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
|
||||
|
||||
$persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association);
|
||||
|
||||
if ($persister->removeElement($this, $element)) {
|
||||
return $element;
|
||||
}
|
||||
|
||||
return null;
|
||||
return $persister->removeElement($this, $element);
|
||||
}
|
||||
|
||||
$removed = parent::removeElement($element);
|
||||
@@ -689,21 +684,41 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
|
||||
protected function doInitialize()
|
||||
{
|
||||
// Has NEW objects added through add(). Remember them.
|
||||
$newObjects = array();
|
||||
$newlyAddedDirtyObjects = array();
|
||||
|
||||
if ($this->isDirty) {
|
||||
$newObjects = $this->collection->toArray();
|
||||
$newlyAddedDirtyObjects = $this->collection->toArray();
|
||||
}
|
||||
|
||||
$this->collection->clear();
|
||||
$this->em->getUnitOfWork()->loadCollection($this);
|
||||
$this->takeSnapshot();
|
||||
|
||||
// Reattach NEW objects added through add(), if any.
|
||||
if ($newObjects) {
|
||||
foreach ($newObjects as $obj) {
|
||||
$this->collection->add($obj);
|
||||
}
|
||||
if ($newlyAddedDirtyObjects) {
|
||||
$this->restoreNewObjectsInDirtyCollection($newlyAddedDirtyObjects);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object[] $newObjects
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* Note: the only reason why this entire looping/complexity is performed via `spl_object_hash`
|
||||
* is because we want to prevent using `array_udiff()`, which is likely to cause very
|
||||
* high overhead (complexity of O(n^2)). `array_diff_key()` performs the operation in
|
||||
* core, which is faster than using a callback for comparisons
|
||||
*/
|
||||
private function restoreNewObjectsInDirtyCollection(array $newObjects)
|
||||
{
|
||||
$loadedObjects = $this->collection->toArray();
|
||||
$newObjectsByOid = \array_combine(\array_map('spl_object_hash', $newObjects), $newObjects);
|
||||
$loadedObjectsByOid = \array_combine(\array_map('spl_object_hash', $loadedObjects), $loadedObjects);
|
||||
$newObjectsThatWereNotLoaded = \array_diff_key($newObjectsByOid, $loadedObjectsByOid);
|
||||
|
||||
if ($newObjectsThatWereNotLoaded) {
|
||||
// Reattach NEW objects added through add(), if any.
|
||||
\array_walk($newObjectsThatWereNotLoaded, [$this->collection, 'add']);
|
||||
|
||||
$this->isDirty = true;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class ResultSetMappingBuilder extends ResultSetMapping
|
||||
* @param string $class The class name of the joined entity.
|
||||
* @param string $alias The unique alias to use for the joined entity.
|
||||
* @param string $parentAlias The alias of the entity result that is the parent of this joined result.
|
||||
* @param object $relation The association field that connects the parent entity result
|
||||
* @param string $relation The association field that connects the parent entity result
|
||||
* with the joined entity result.
|
||||
* @param array $renamedColumns Columns that have been renamed (tableColumnName => queryColumnName).
|
||||
* @param int|null $renameMode One of the COLUMN_RENAMING_* constants or array for BC reasons (CUSTOM).
|
||||
|
||||
@@ -870,6 +870,19 @@ class SqlWalker implements TreeWalker
|
||||
* @return string
|
||||
*/
|
||||
public function walkRangeVariableDeclaration($rangeVariableDeclaration)
|
||||
{
|
||||
return $this->generateRangeVariableDeclarationSQL($rangeVariableDeclaration, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate appropriate SQL for RangeVariableDeclaration AST node
|
||||
*
|
||||
* @param AST\RangeVariableDeclaration $rangeVariableDeclaration
|
||||
* @param bool $buildNestedJoins
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateRangeVariableDeclarationSQL($rangeVariableDeclaration, $buildNestedJoins)
|
||||
{
|
||||
$class = $this->em->getClassMetadata($rangeVariableDeclaration->abstractSchemaName);
|
||||
$dqlAlias = $rangeVariableDeclaration->aliasIdentificationVariable;
|
||||
@@ -885,7 +898,11 @@ class SqlWalker implements TreeWalker
|
||||
);
|
||||
|
||||
if ($class->isInheritanceTypeJoined()) {
|
||||
$sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias);
|
||||
if ($buildNestedJoins) {
|
||||
$sql = '(' . $sql . $this->_generateClassTableInheritanceJoins($class, $dqlAlias) . ')';
|
||||
} else {
|
||||
$sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias);
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
@@ -1121,16 +1138,17 @@ class SqlWalker implements TreeWalker
|
||||
: ' INNER JOIN ';
|
||||
|
||||
switch (true) {
|
||||
case ($joinDeclaration instanceof \Doctrine\ORM\Query\AST\RangeVariableDeclaration):
|
||||
case ($joinDeclaration instanceof AST\RangeVariableDeclaration):
|
||||
$class = $this->em->getClassMetadata($joinDeclaration->abstractSchemaName);
|
||||
$dqlAlias = $joinDeclaration->aliasIdentificationVariable;
|
||||
$tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias);
|
||||
$condition = '(' . $this->walkConditionalExpression($join->conditionalExpression) . ')';
|
||||
$condExprConjunction = ($class->isInheritanceTypeJoined() && $joinType != AST\Join::JOIN_TYPE_LEFT && $joinType != AST\Join::JOIN_TYPE_LEFTOUTER)
|
||||
$isUnconditionalJoin = empty($condition);
|
||||
$condExprConjunction = ($class->isInheritanceTypeJoined() && $joinType != AST\Join::JOIN_TYPE_LEFT && $joinType != AST\Join::JOIN_TYPE_LEFTOUTER && $isUnconditionalJoin)
|
||||
? ' AND '
|
||||
: ' ON ';
|
||||
|
||||
$sql .= $this->walkRangeVariableDeclaration($joinDeclaration);
|
||||
$sql .= $this->generateRangeVariableDeclarationSQL($joinDeclaration, !$isUnconditionalJoin);
|
||||
|
||||
$conditions = array($condition);
|
||||
|
||||
@@ -1151,7 +1169,7 @@ class SqlWalker implements TreeWalker
|
||||
$sql .= $condExprConjunction . implode(' AND ', $conditions);
|
||||
break;
|
||||
|
||||
case ($joinDeclaration instanceof \Doctrine\ORM\Query\AST\JoinAssociationDeclaration):
|
||||
case ($joinDeclaration instanceof AST\JoinAssociationDeclaration):
|
||||
$sql .= $this->walkJoinAssociationDeclaration($joinDeclaration, $joinType, $join->conditionalExpression);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -84,10 +84,6 @@ class MetadataFilter extends \FilterIterator implements \Countable
|
||||
);
|
||||
}
|
||||
|
||||
if ($pregResult === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($pregResult) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -85,6 +85,14 @@ class CountOutputWalker extends SqlWalker
|
||||
|
||||
$sql = parent::walkSelectStatement($AST);
|
||||
|
||||
if ($AST->groupByClause) {
|
||||
return sprintf(
|
||||
'SELECT %s AS dctrn_count FROM (%s) dctrn_table',
|
||||
$this->platform->getCountExpression('*'),
|
||||
$sql
|
||||
);
|
||||
}
|
||||
|
||||
// Find out the SQL alias of the identifier column of the root entity
|
||||
// It may be possible to make this work with multiple root entities but that
|
||||
// would probably require issuing multiple queries or doing a UNION SELECT
|
||||
|
||||
@@ -345,7 +345,7 @@ class SchemaTool
|
||||
$discrColumn = $class->discriminatorColumn;
|
||||
|
||||
if ( ! isset($discrColumn['type']) ||
|
||||
(strtolower($discrColumn['type']) == 'string' && $discrColumn['length'] === null)
|
||||
(strtolower($discrColumn['type']) == 'string' && ! isset($discrColumn['length']))
|
||||
) {
|
||||
$discrColumn['type'] = 'string';
|
||||
$discrColumn['length'] = 255;
|
||||
|
||||
@@ -36,7 +36,7 @@ class Version
|
||||
/**
|
||||
* Current Doctrine Version
|
||||
*/
|
||||
const VERSION = '2.5.5-DEV';
|
||||
const VERSION = '2.5.8';
|
||||
|
||||
/**
|
||||
* Compares a Doctrine version with the current one.
|
||||
|
||||
@@ -636,11 +636,13 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase
|
||||
$group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId);
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$user->groups->removeElement($group);
|
||||
$this->assertTrue($user->groups->removeElement($group));
|
||||
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed.");
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||
|
||||
$this->assertFalse($user->groups->removeElement($group), "Removing an already removed element returns false");
|
||||
|
||||
// Test Many to Many removal with Entity state as new
|
||||
$group = new \Doctrine\Tests\Models\CMS\CmsGroup();
|
||||
$group->name = "A New group!";
|
||||
|
||||
65
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php
Normal file
65
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
/**
|
||||
* @group DDC-3146
|
||||
* @author Emiel Nijpels <emiel@silverstreet.com>
|
||||
*/
|
||||
class DDC3146Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
/**
|
||||
* Verify that the number of added events to the event listener from the abstract hydrator class is equal to the number of removed events
|
||||
*/
|
||||
public function testEventListeners()
|
||||
{
|
||||
// Create mock connection to be returned from the entity manager interface
|
||||
$mockConnection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
|
||||
$mockEntityManagerInterface = $this->getMockBuilder('Doctrine\ORM\EntityManagerInterface')->disableOriginalConstructor()->getMock();
|
||||
$mockEntityManagerInterface->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
|
||||
|
||||
// Create mock event manager to be returned from the entity manager interface
|
||||
$mockEventManager = $this->getMockBuilder('Doctrine\Common\EventManager')->disableOriginalConstructor()->getMock();
|
||||
$mockEntityManagerInterface->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager));
|
||||
|
||||
// Create mock statement and result mapping
|
||||
$mockStatement = $this->getMockBuilder('Doctrine\DBAL\Driver\Statement')->disableOriginalConstructor()->getMock();
|
||||
$mockStatement->expects($this->once())->method('fetch')->will($this->returnValue(false));
|
||||
$mockResultMapping = $this->getMockBuilder('Doctrine\ORM\Query\ResultSetMapping')->disableOriginalConstructor()->getMock();
|
||||
|
||||
// Create mock abstract hydrator
|
||||
$mockAbstractHydrator = $this->getMockBuilder('Doctrine\ORM\Internal\Hydration\AbstractHydrator')
|
||||
->setConstructorArgs(array($mockEntityManagerInterface))
|
||||
->setMethods(array('hydrateAllData'))
|
||||
->getMock();
|
||||
|
||||
// Increase counter every time the event listener is added and decrease the counter every time the event listener is removed
|
||||
$eventCounter = 0;
|
||||
$mockEventManager->expects($this->any())
|
||||
->method('addEventListener')
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () use (&$eventCounter) {
|
||||
$eventCounter++;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$mockEventManager->expects($this->any())
|
||||
->method('removeEventListener')
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function () use (&$eventCounter) {
|
||||
$eventCounter--;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// Create iterable result
|
||||
$iterableResult = $mockAbstractHydrator->iterate($mockStatement, $mockResultMapping, array());
|
||||
$iterableResult->next();
|
||||
|
||||
// Number of added events listeners should be equal or less than the number of removed events
|
||||
$this->assertLessThanOrEqual(0, $eventCounter, 'More events added to the event listener than removed; this can create a memory leak when references are not cleaned up');
|
||||
}
|
||||
}
|
||||
152
tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php
Normal file
152
tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
use Doctrine\Tests\Mocks\HydratorMockStatement;
|
||||
|
||||
final class GH6362Test extends OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_schemaTool->createSchema(
|
||||
[
|
||||
$this->_em->getClassMetadata(GH6362Start::CLASSNAME),
|
||||
$this->_em->getClassMetadata(GH6362Base::CLASSNAME),
|
||||
$this->_em->getClassMetadata(GH6362Child::CLASSNAME),
|
||||
$this->_em->getClassMetadata(GH6362Join::CLASSNAME),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 6362
|
||||
*
|
||||
* SELECT a as base, b, c, d
|
||||
* FROM Start a
|
||||
* LEFT JOIN a.bases b
|
||||
* LEFT JOIN Child c WITH b.id = c.id
|
||||
* LEFT JOIN c.joins d
|
||||
*/
|
||||
public function testInheritanceJoinAlias()
|
||||
{
|
||||
$rsm = new ResultSetMapping;
|
||||
$rsm->addEntityResult(GH6362Start::CLASSNAME, 'a', 'base');
|
||||
$rsm->addJoinedEntityResult(GH6362Base::CLASSNAME, 'b', 'a', 'bases');
|
||||
$rsm->addEntityResult(GH6362Child::CLASSNAME, 'c');
|
||||
$rsm->addJoinedEntityResult(GH6362Join::CLASSNAME, 'd', 'c', 'joins');
|
||||
|
||||
$rsm->addFieldResult('a', 'id_0', 'id');
|
||||
$rsm->addFieldResult('b', 'id_1', 'id');
|
||||
$rsm->addFieldResult('c', 'id_2', 'id');
|
||||
$rsm->addFieldResult('d', 'id_3', 'id');
|
||||
|
||||
$rsm->addMetaResult('a', 'bases_id_4', 'bases_id', false, 'integer');
|
||||
$rsm->addMetaResult('b', 'type_5', 'type');
|
||||
$rsm->addMetaResult('c', 'type_6', 'type');
|
||||
$rsm->addMetaResult('d', 'child_id_7', 'child_id', false, 'integer');
|
||||
|
||||
$rsm->setDiscriminatorColumn('b', 'type_5');
|
||||
$rsm->setDiscriminatorColumn('c', 'type_6');
|
||||
|
||||
$resultSet = [
|
||||
[
|
||||
'id_0' => '1',
|
||||
'id_1' => '1',
|
||||
'id_2' => '1',
|
||||
'id_3' => '1',
|
||||
'bases_id_4' => '1',
|
||||
'type_5' => 'child',
|
||||
'type_6' => 'child',
|
||||
'child_id_7' => '1',
|
||||
],
|
||||
];
|
||||
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]);
|
||||
|
||||
$this->assertInstanceOf(GH6362Start::CLASSNAME, $result[0]['base']);
|
||||
$this->assertInstanceOf(GH6362Child::CLASSNAME, $result[1][0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class GH6362Start
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/**
|
||||
* @Column(type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="GH6362Base", inversedBy="starts")
|
||||
*/
|
||||
private $bases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @InheritanceType("SINGLE_TABLE")
|
||||
* @DiscriminatorColumn(name="type", type="string")
|
||||
* @DiscriminatorMap({"child" = "GH6362Child"})
|
||||
* @Entity
|
||||
*/
|
||||
abstract class GH6362Base
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/**
|
||||
* @Column(type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="GH6362Start", mappedBy="bases")
|
||||
*/
|
||||
private $starts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class GH6362Child extends GH6362Base
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="GH6362Join", mappedBy="child")
|
||||
*/
|
||||
private $joins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class GH6362Join
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/**
|
||||
* @Column(type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="GH6362Child", inversedBy="joins")
|
||||
*/
|
||||
private $child;
|
||||
}
|
||||
81
tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php
Normal file
81
tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @group GH-6464
|
||||
*/
|
||||
class GH6464Test extends OrmFunctionalTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_schemaTool->createSchema([
|
||||
$this->_em->getClassMetadata(GH6464Post::CLASS_NAME),
|
||||
$this->_em->getClassMetadata(GH6464User::CLASS_NAME),
|
||||
$this->_em->getClassMetadata(GH6464Author::CLASS_NAME),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that SqlWalker generates valid SQL for an INNER JOIN to CTI table
|
||||
*
|
||||
* SqlWalker needs to generate nested INNER JOIN statements, otherwise there would be INNER JOIN
|
||||
* statements without an ON clause, which are valid on e.g. MySQL but rejected by PostgreSQL.
|
||||
*/
|
||||
public function testIssue()
|
||||
{
|
||||
$query = $this->_em->createQueryBuilder()
|
||||
->select('p')
|
||||
->from(GH6464Post::CLASS_NAME, 'p')
|
||||
->innerJoin(GH6464Author::CLASS_NAME, 'a', 'WITH', 'p.authorId = a.id')
|
||||
->getQuery();
|
||||
|
||||
$this->assertNotRegExp(
|
||||
'/INNER JOIN \w+ \w+ INNER JOIN/',
|
||||
$query->getSQL(),
|
||||
'As of GH-6464, every INNER JOIN should have an ON clause, which is missing here'
|
||||
);
|
||||
|
||||
// Query shouldn't yield a result, yet it shouldn't crash (anymore)
|
||||
$this->assertEquals([], $query->getResult());
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class GH6464Post
|
||||
{
|
||||
const CLASS_NAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
public $id;
|
||||
|
||||
/** @Column(type="integer") */
|
||||
public $authorId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorColumn(name="discr", type="string")
|
||||
* @DiscriminatorMap({"author" = "GH6464Author"})
|
||||
*/
|
||||
abstract class GH6464User
|
||||
{
|
||||
const CLASS_NAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
public $id;
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class GH6464Author extends GH6464User
|
||||
{
|
||||
const CLASS_NAME = __CLASS__;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\PersistentCollection;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
use Doctrine\Tests\Mocks\ConnectionMock;
|
||||
use Doctrine\Tests\Mocks\DriverMock;
|
||||
use Doctrine\Tests\Mocks\EntityManagerMock;
|
||||
@@ -23,7 +24,7 @@ class PersistentCollectionTest extends OrmTestCase
|
||||
protected $collection;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\ORM\EntityManagerInterface
|
||||
* @var EntityManagerMock
|
||||
*/
|
||||
private $_emMock;
|
||||
|
||||
@@ -32,6 +33,8 @@ class PersistentCollectionTest extends OrmTestCase
|
||||
parent::setUp();
|
||||
|
||||
$this->_emMock = EntityManagerMock::create(new ConnectionMock([], new DriverMock()));
|
||||
|
||||
$this->setUpPersistentCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +61,6 @@ class PersistentCollectionTest extends OrmTestCase
|
||||
*/
|
||||
public function testCurrentInitializesCollection()
|
||||
{
|
||||
$this->setUpPersistentCollection();
|
||||
$this->collection->current();
|
||||
$this->assertTrue($this->collection->isInitialized());
|
||||
}
|
||||
@@ -68,7 +70,6 @@ class PersistentCollectionTest extends OrmTestCase
|
||||
*/
|
||||
public function testKeyInitializesCollection()
|
||||
{
|
||||
$this->setUpPersistentCollection();
|
||||
$this->collection->key();
|
||||
$this->assertTrue($this->collection->isInitialized());
|
||||
}
|
||||
@@ -78,7 +79,6 @@ class PersistentCollectionTest extends OrmTestCase
|
||||
*/
|
||||
public function testNextInitializesCollection()
|
||||
{
|
||||
$this->setUpPersistentCollection();
|
||||
$this->collection->next();
|
||||
$this->assertTrue($this->collection->isInitialized());
|
||||
}
|
||||
@@ -88,12 +88,12 @@ class PersistentCollectionTest extends OrmTestCase
|
||||
*/
|
||||
public function testRemovingElementsAlsoRemovesKeys()
|
||||
{
|
||||
$this->setUpPersistentCollection();
|
||||
$dummy = new \stdClass();
|
||||
|
||||
$this->collection->add('dummy');
|
||||
$this->collection->add($dummy);
|
||||
$this->assertEquals([0], array_keys($this->collection->toArray()));
|
||||
|
||||
$this->collection->removeElement('dummy');
|
||||
$this->collection->removeElement($dummy);
|
||||
$this->assertEquals([], array_keys($this->collection->toArray()));
|
||||
}
|
||||
|
||||
@@ -102,9 +102,7 @@ class PersistentCollectionTest extends OrmTestCase
|
||||
*/
|
||||
public function testClearWillAlsoClearKeys()
|
||||
{
|
||||
$this->setUpPersistentCollection();
|
||||
|
||||
$this->collection->add('dummy');
|
||||
$this->collection->add(new \stdClass());
|
||||
$this->collection->clear();
|
||||
$this->assertEquals([], array_keys($this->collection->toArray()));
|
||||
}
|
||||
@@ -114,12 +112,142 @@ class PersistentCollectionTest extends OrmTestCase
|
||||
*/
|
||||
public function testClearWillAlsoResetKeyPositions()
|
||||
{
|
||||
$this->setUpPersistentCollection();
|
||||
$dummy = new \stdClass();
|
||||
|
||||
$this->collection->add('dummy');
|
||||
$this->collection->removeElement('dummy');
|
||||
$this->collection->add($dummy);
|
||||
$this->collection->removeElement($dummy);
|
||||
$this->collection->clear();
|
||||
$this->collection->add('dummy');
|
||||
$this->collection->add($dummy);
|
||||
$this->assertEquals([0], array_keys($this->collection->toArray()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 6613
|
||||
* @group 6614
|
||||
* @group 6616
|
||||
*/
|
||||
public function testWillKeepNewItemsInDirtyCollectionAfterInitialization()
|
||||
{
|
||||
/* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */
|
||||
$unitOfWork = $this
|
||||
->getMockBuilder('Doctrine\ORM\UnitOfWork')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->_emMock->setUnitOfWork($unitOfWork);
|
||||
|
||||
$newElement = new \stdClass();
|
||||
$persistedElement = new \stdClass();
|
||||
|
||||
$this->collection->add($newElement);
|
||||
|
||||
self::assertFalse($this->collection->isInitialized());
|
||||
self::assertTrue($this->collection->isDirty());
|
||||
|
||||
$unitOfWork
|
||||
->expects(self::once())
|
||||
->method('loadCollection')
|
||||
->with($this->collection)
|
||||
->willReturnCallback(function (PersistentCollection $persistentCollection) use ($persistedElement) {
|
||||
$persistentCollection->unwrap()->add($persistedElement);
|
||||
});
|
||||
|
||||
$this->collection->initialize();
|
||||
|
||||
self::assertSame([$persistedElement, $newElement], $this->collection->toArray());
|
||||
self::assertTrue($this->collection->isInitialized());
|
||||
self::assertTrue($this->collection->isDirty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 6613
|
||||
* @group 6614
|
||||
* @group 6616
|
||||
*/
|
||||
public function testWillDeDuplicateNewItemsThatWerePreviouslyPersistedInDirtyCollectionAfterInitialization()
|
||||
{
|
||||
/* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */
|
||||
$unitOfWork = $this
|
||||
->getMockBuilder('Doctrine\ORM\UnitOfWork')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->_emMock->setUnitOfWork($unitOfWork);
|
||||
|
||||
$newElement = new \stdClass();
|
||||
$newElementThatIsAlsoPersisted = new \stdClass();
|
||||
$persistedElement = new \stdClass();
|
||||
|
||||
$this->collection->add($newElementThatIsAlsoPersisted);
|
||||
$this->collection->add($newElement);
|
||||
|
||||
self::assertFalse($this->collection->isInitialized());
|
||||
self::assertTrue($this->collection->isDirty());
|
||||
|
||||
$unitOfWork
|
||||
->expects(self::once())
|
||||
->method('loadCollection')
|
||||
->with($this->collection)
|
||||
->willReturnCallback(function (PersistentCollection $persistentCollection) use (
|
||||
$persistedElement,
|
||||
$newElementThatIsAlsoPersisted
|
||||
) {
|
||||
$persistentCollection->unwrap()->add($newElementThatIsAlsoPersisted);
|
||||
$persistentCollection->unwrap()->add($persistedElement);
|
||||
});
|
||||
|
||||
$this->collection->initialize();
|
||||
|
||||
self::assertSame(
|
||||
[$newElementThatIsAlsoPersisted, $persistedElement, $newElement],
|
||||
$this->collection->toArray()
|
||||
);
|
||||
self::assertTrue($this->collection->isInitialized());
|
||||
self::assertTrue($this->collection->isDirty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group 6613
|
||||
* @group 6614
|
||||
* @group 6616
|
||||
*/
|
||||
public function testWillNotMarkCollectionAsDirtyAfterInitializationIfNoElementsWereAdded()
|
||||
{
|
||||
/* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */
|
||||
$unitOfWork = $this
|
||||
->getMockBuilder('Doctrine\ORM\UnitOfWork')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->_emMock->setUnitOfWork($unitOfWork);
|
||||
|
||||
$newElementThatIsAlsoPersisted = new \stdClass();
|
||||
$persistedElement = new \stdClass();
|
||||
|
||||
$this->collection->add($newElementThatIsAlsoPersisted);
|
||||
|
||||
self::assertFalse($this->collection->isInitialized());
|
||||
self::assertTrue($this->collection->isDirty());
|
||||
|
||||
$unitOfWork
|
||||
->expects(self::once())
|
||||
->method('loadCollection')
|
||||
->with($this->collection)
|
||||
->willReturnCallback(function (PersistentCollection $persistentCollection) use (
|
||||
$persistedElement,
|
||||
$newElementThatIsAlsoPersisted
|
||||
) {
|
||||
$persistentCollection->unwrap()->add($newElementThatIsAlsoPersisted);
|
||||
$persistentCollection->unwrap()->add($persistedElement);
|
||||
});
|
||||
|
||||
$this->collection->initialize();
|
||||
|
||||
self::assertSame(
|
||||
[$newElementThatIsAlsoPersisted, $persistedElement],
|
||||
$this->collection->toArray()
|
||||
);
|
||||
self::assertTrue($this->collection->isInitialized());
|
||||
self::assertFalse($this->collection->isDirty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,12 +153,12 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
$this->assertSqlGeneration(
|
||||
'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e JOIN Doctrine\Tests\Models\Company\CompanyManager m WITH e.id = m.id',
|
||||
'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id INNER JOIN company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id AND (c0_.id = c3_.id)'
|
||||
'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id INNER JOIN (company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id) ON (c0_.id = c3_.id)'
|
||||
);
|
||||
|
||||
$this->assertSqlGeneration(
|
||||
'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e LEFT JOIN Doctrine\Tests\Models\Company\CompanyManager m WITH e.id = m.id',
|
||||
'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id ON (c0_.id = c3_.id)'
|
||||
'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN (company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id) ON (c0_.id = c3_.id)'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2165,7 +2165,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
// the where clause when not joining onto that table
|
||||
$this->assertSqlGeneration(
|
||||
'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c LEFT JOIN Doctrine\Tests\Models\Company\CompanyEmployee e WITH e.id = c.salesPerson WHERE c.completed = true',
|
||||
"SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ LEFT JOIN company_employees c1_ INNER JOIN company_persons c2_ ON c1_.id = c2_.id ON (c2_.id = c0_.salesPerson_id) WHERE (c0_.completed = 1) AND c0_.discr IN ('fix', 'flexible', 'flexultra')"
|
||||
"SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ LEFT JOIN (company_employees c1_ INNER JOIN company_persons c2_ ON c1_.id = c2_.id) ON (c2_.id = c0_.salesPerson_id) WHERE (c0_.completed = 1) AND c0_.discr IN ('fix', 'flexible', 'flexultra')"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
195
tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php
Normal file
195
tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Console;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\MetadataFilter;
|
||||
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
|
||||
|
||||
/**
|
||||
* Tests for {@see \Doctrine\ORM\Tools\Console\MetadataFilter}
|
||||
*
|
||||
* @covers \Doctrine\ORM\Tools\Console\MetadataFilter
|
||||
*/
|
||||
class MetadataFilterTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
/**
|
||||
* @var DisconnectedClassMetadataFactory
|
||||
*/
|
||||
private $cmf;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$driver = $this->createAnnotationDriver();
|
||||
$em = $this->_getTestEntityManager();
|
||||
$em->getConfiguration()->setMetadataDriverImpl($driver);
|
||||
|
||||
$this->cmf = new DisconnectedClassMetadataFactory();
|
||||
$this->cmf->setEntityManager($em);
|
||||
}
|
||||
|
||||
public function testFilterWithEmptyArray()
|
||||
{
|
||||
$originalMetadatas = array(
|
||||
$metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME),
|
||||
$metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::CLASSNAME),
|
||||
);
|
||||
|
||||
$metadatas = $originalMetadatas;
|
||||
$metadatas = MetadataFilter::filter($metadatas, array());
|
||||
|
||||
$this->assertContains($metadataAaa, $metadatas);
|
||||
$this->assertContains($metadataBbb, $metadatas);
|
||||
$this->assertCount(count($originalMetadatas), $metadatas);
|
||||
}
|
||||
|
||||
public function testFilterWithString()
|
||||
{
|
||||
$originalMetadatas = array(
|
||||
$metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME),
|
||||
$metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::CLASSNAME),
|
||||
$metadataCcc = $this->cmf->getMetadataFor(MetadataFilterTestEntityCcc::CLASSNAME),
|
||||
);
|
||||
|
||||
$metadatas = $originalMetadatas;
|
||||
$metadatas = MetadataFilter::filter($metadatas, 'MetadataFilterTestEntityAaa');
|
||||
|
||||
$this->assertContains($metadataAaa, $metadatas);
|
||||
$this->assertNotContains($metadataBbb, $metadatas);
|
||||
$this->assertNotContains($metadataCcc, $metadatas);
|
||||
$this->assertCount(1, $metadatas);
|
||||
|
||||
$metadatas = $originalMetadatas;
|
||||
$metadatas = MetadataFilter::filter($metadatas, 'MetadataFilterTestEntityBbb');
|
||||
|
||||
$this->assertNotContains($metadataAaa, $metadatas);
|
||||
$this->assertContains($metadataBbb, $metadatas);
|
||||
$this->assertNotContains($metadataCcc, $metadatas);
|
||||
$this->assertCount(1, $metadatas);
|
||||
|
||||
$metadatas = $originalMetadatas;
|
||||
$metadatas = MetadataFilter::filter($metadatas, 'MetadataFilterTestEntityCcc');
|
||||
|
||||
$this->assertNotContains($metadataAaa, $metadatas);
|
||||
$this->assertNotContains($metadataBbb, $metadatas);
|
||||
$this->assertContains($metadataCcc, $metadatas);
|
||||
$this->assertCount(1, $metadatas);
|
||||
}
|
||||
|
||||
public function testFilterWithString2()
|
||||
{
|
||||
$originalMetadatas = array(
|
||||
$metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::CLASSNAME),
|
||||
$metadataFooBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityFooBar::CLASSNAME),
|
||||
$metadataBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityBar::CLASSNAME),
|
||||
);
|
||||
|
||||
$metadatas = $originalMetadatas;
|
||||
$metadatas = MetadataFilter::filter($metadatas, 'MetadataFilterTestEntityFoo');
|
||||
|
||||
$this->assertContains($metadataFoo, $metadatas);
|
||||
$this->assertContains($metadataFooBar, $metadatas);
|
||||
$this->assertNotContains($metadataBar, $metadatas);
|
||||
$this->assertCount(2, $metadatas);
|
||||
}
|
||||
|
||||
public function testFilterWithArray()
|
||||
{
|
||||
$originalMetadatas = array(
|
||||
$metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME),
|
||||
$metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::CLASSNAME),
|
||||
$metadataCcc = $this->cmf->getMetadataFor(MetadataFilterTestEntityCcc::CLASSNAME),
|
||||
);
|
||||
|
||||
$metadatas = $originalMetadatas;
|
||||
$metadatas = MetadataFilter::filter($metadatas, array(
|
||||
'MetadataFilterTestEntityAaa',
|
||||
'MetadataFilterTestEntityCcc',
|
||||
));
|
||||
|
||||
$this->assertContains($metadataAaa, $metadatas);
|
||||
$this->assertNotContains($metadataBbb, $metadatas);
|
||||
$this->assertContains($metadataCcc, $metadatas);
|
||||
$this->assertCount(2, $metadatas);
|
||||
}
|
||||
|
||||
public function testFilterWithRegex()
|
||||
{
|
||||
$originalMetadatas = array(
|
||||
$metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::CLASSNAME),
|
||||
$metadataFooBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityFooBar::CLASSNAME),
|
||||
$metadataBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityBar::CLASSNAME),
|
||||
);
|
||||
|
||||
$metadatas = $originalMetadatas;
|
||||
$metadatas = MetadataFilter::filter($metadatas, 'Foo$');
|
||||
|
||||
$this->assertContains($metadataFoo, $metadatas);
|
||||
$this->assertNotContains($metadataFooBar, $metadatas);
|
||||
$this->assertNotContains($metadataBar, $metadatas);
|
||||
$this->assertCount(1, $metadatas);
|
||||
|
||||
$metadatas = $originalMetadatas;
|
||||
$metadatas = MetadataFilter::filter($metadatas, 'Bar$');
|
||||
|
||||
$this->assertNotContains($metadataFoo, $metadatas);
|
||||
$this->assertContains($metadataFooBar, $metadatas);
|
||||
$this->assertContains($metadataBar, $metadatas);
|
||||
$this->assertCount(2, $metadatas);
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class MetadataFilterTestEntityAaa
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") */
|
||||
protected $id;
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class MetadataFilterTestEntityBbb
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") */
|
||||
protected $id;
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class MetadataFilterTestEntityCcc
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") */
|
||||
protected $id;
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class MetadataFilterTestEntityFoo
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") */
|
||||
protected $id;
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class MetadataFilterTestEntityBar
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") */
|
||||
protected $id;
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class MetadataFilterTestEntityFooBar
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") */
|
||||
protected $id;
|
||||
}
|
||||
@@ -30,6 +30,18 @@ class CountOutputWalkerTest extends PaginationTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testCountQuery_GroupBy()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT p.name FROM Doctrine\Tests\ORM\Tools\Pagination\Person p GROUP BY p.name');
|
||||
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
|
||||
$query->setFirstResult(null)->setMaxResults(null);
|
||||
|
||||
$this->assertSame(
|
||||
"SELECT COUNT(*) AS dctrn_count FROM (SELECT p0_.name AS name_0 FROM Person p0_ GROUP BY p0_.name) dctrn_table", $query->getSQL()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCountQuery_Having()
|
||||
{
|
||||
$query = $this->entityManager->createQuery(
|
||||
@@ -37,8 +49,8 @@ class CountOutputWalkerTest extends PaginationTestCase
|
||||
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
|
||||
$query->setFirstResult(null)->setMaxResults(null);
|
||||
|
||||
$this->assertEquals(
|
||||
"SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id_1 FROM (SELECT count(u0_.id) AS sclr_0, g1_.id AS id_1, u0_.id AS id_2 FROM groups g1_ LEFT JOIN user_group u2_ ON g1_.id = u2_.group_id LEFT JOIN User u0_ ON u0_.id = u2_.user_id GROUP BY g1_.id HAVING sclr_0 > 0) dctrn_result) dctrn_table", $query->getSql()
|
||||
$this->assertSame(
|
||||
"SELECT COUNT(*) AS dctrn_count FROM (SELECT count(u0_.id) AS sclr_0, g1_.id AS id_1, u0_.id AS id_2 FROM groups g1_ LEFT JOIN user_group u2_ ON g1_.id = u2_.group_id LEFT JOIN User u0_ ON u0_.id = u2_.user_id GROUP BY g1_.id HAVING sclr_0 > 0) dctrn_table", $query->getSQL()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools;
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
|
||||
use Doctrine\ORM\Tools\Event\GenerateSchemaTableEventArgs;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Doctrine\ORM\Tools\ToolEvents;
|
||||
use Doctrine\ORM\Tools\Event\GenerateSchemaTableEventArgs;
|
||||
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
|
||||
|
||||
class SchemaToolTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
@@ -138,6 +139,26 @@ class SchemaToolTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertTrue($table->hasIndex('primary'));
|
||||
$this->assertTrue($table->hasIndex('uniq_hash'));
|
||||
}
|
||||
|
||||
public function testSetDiscriminatorColumnWithoutLength()
|
||||
{
|
||||
$em = $this->_getTestEntityManager();
|
||||
$schemaTool = new SchemaTool($em);
|
||||
$metadata = $em->getClassMetadata(__NAMESPACE__ . '\\FirstEntity');
|
||||
|
||||
$metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE);
|
||||
$metadata->setDiscriminatorColumn(['name' => 'discriminator', 'type' => 'string']);
|
||||
|
||||
$schema = $schemaTool->getSchemaFromMetadata([$metadata]);
|
||||
|
||||
$this->assertTrue($schema->hasTable('first_entity'));
|
||||
$table = $schema->getTable('first_entity');
|
||||
|
||||
$this->assertTrue($table->hasColumn('discriminator'));
|
||||
$column = $table->getColumn('discriminator');
|
||||
|
||||
$this->assertEquals(255, $column->getLength());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,3 +208,45 @@ class UniqueConstraintAnnotationModel
|
||||
*/
|
||||
private $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="first_entity")
|
||||
*/
|
||||
class FirstEntity
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(name="id")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @OneToOne(targetEntity="SecondEntity")
|
||||
* @JoinColumn(name="id", referencedColumnName="fist_entity_id")
|
||||
*/
|
||||
public $secondEntity;
|
||||
|
||||
/**
|
||||
* @Column(name="name")
|
||||
*/
|
||||
public $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="second_entity")
|
||||
*/
|
||||
class SecondEntity
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(name="fist_entity_id")
|
||||
*/
|
||||
public $fist_entity_id;
|
||||
|
||||
/**
|
||||
* @Column(name="name")
|
||||
*/
|
||||
public $name;
|
||||
}
|
||||
|
||||
@@ -309,6 +309,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
protected function tearDown()
|
||||
{
|
||||
$conn = static::$_sharedConn;
|
||||
|
||||
// In case test is skipped, tearDown is called, but no setup may have run
|
||||
if ( ! $conn) {
|
||||
return;
|
||||
}
|
||||
|
||||
$platform = $conn->getDatabasePlatform();
|
||||
|
||||
$this->_sqlLoggerStack->enabled = false;
|
||||
|
||||
Reference in New Issue
Block a user