From 1d31b011200084206daf4650e9a274eb1b841948 Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Sat, 30 Jul 2016 22:04:59 +0200 Subject: [PATCH] Remove requireIndexes and stuff thereto related --- doctrine-mongo-mapping.xsd | 1 - .../MongoDB/Mapping/Annotations/Document.php | 1 - .../ODM/MongoDB/Mapping/ClassMetadataInfo.php | 15 - .../Mapping/Driver/AnnotationDriver.php | 3 - .../ODM/MongoDB/Mapping/Driver/XmlDriver.php | 3 - .../ODM/MongoDB/Mapping/Driver/YamlDriver.php | 3 - lib/Doctrine/ODM/MongoDB/MongoDBException.php | 13 - lib/Doctrine/ODM/MongoDB/Query/Builder.php | 20 -- .../ODM/MongoDB/Query/FieldExtractor.php | 94 ----- lib/Doctrine/ODM/MongoDB/Query/Query.php | 72 +--- .../Tests/Functional/GeoSpatialTest.php | 8 - .../Tests/Functional/RequireIndexesTest.php | 321 ------------------ .../Tests/Mapping/Driver/XmlDriverTest.php | 1 - ...TestDocuments.UserNonStringOptions.dcm.xml | 26 +- .../Tests/Query/FieldExtractorTest.php | 88 ----- 15 files changed, 14 insertions(+), 655 deletions(-) delete mode 100644 lib/Doctrine/ODM/MongoDB/Query/FieldExtractor.php delete mode 100644 tests/Doctrine/ODM/MongoDB/Tests/Functional/RequireIndexesTest.php delete mode 100644 tests/Doctrine/ODM/MongoDB/Tests/Query/FieldExtractorTest.php diff --git a/doctrine-mongo-mapping.xsd b/doctrine-mongo-mapping.xsd index 57a60acd86..0ba9eb5f25 100644 --- a/doctrine-mongo-mapping.xsd +++ b/doctrine-mongo-mapping.xsd @@ -55,7 +55,6 @@ - diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Document.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Document.php index 6c3146b6e7..fb2317c68e 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Document.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Document.php @@ -30,7 +30,6 @@ final class Document extends AbstractDocument public $collection; public $repositoryClass; public $indexes = array(); - public $requireIndexes = false; public $shardKey; public $slaveOkay; public $writeConcern; diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php index 85653d2f96..cef577dcee 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php @@ -225,11 +225,6 @@ class ClassMetadataInfo implements \Doctrine\Common\Persistence\Mapping\ClassMet */ public $shardKey; - /** - * READ-ONLY: Whether or not queries on this document should require indexes. - */ - public $requireIndexes = false; - /** * READ-ONLY: The name of the document class. */ @@ -803,16 +798,6 @@ public function addIndex($keys, array $options = array()) ); } - /** - * Set whether or not queries on this document should require indexes. - * - * @param bool $requireIndexes - */ - public function setRequireIndexes($requireIndexes) - { - $this->requireIndexes = $requireIndexes; - } - /** * Returns the array of indexes for this Document. * diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php index 4b8e71bbc3..3e8802bfd1 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php @@ -135,9 +135,6 @@ public function loadMetadataForClass($className, ClassMetadata $class) $this->addIndex($class, $index); } } - if (isset($documentAnnot->requireIndexes)) { - $class->setRequireIndexes($documentAnnot->requireIndexes); - } if (isset($documentAnnot->slaveOkay)) { $class->setSlaveOkay($documentAnnot->slaveOkay); } diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php index 82e4408a33..1b05404b12 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php @@ -121,9 +121,6 @@ public function loadMetadataForClass($className, ClassMetadata $class) if (isset($xmlRoot->{'shard-key'})) { $this->setShardKey($class, $xmlRoot->{'shard-key'}[0]); } - if (isset($xmlRoot['require-indexes'])) { - $class->setRequireIndexes('true' === (string) $xmlRoot['require-indexes']); - } if (isset($xmlRoot['slave-okay'])) { $class->setSlaveOkay('true' === (string) $xmlRoot['slave-okay']); } diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/YamlDriver.php index 95fd1fdaab..e9a5dd52a8 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/YamlDriver.php @@ -100,9 +100,6 @@ public function loadMetadataForClass($className, ClassMetadata $class) if (isset($element['changeTrackingPolicy'])) { $class->setChangeTrackingPolicy(constant(MappingClassMetadata::class . '::CHANGETRACKING_' . strtoupper($element['changeTrackingPolicy']))); } - if (isset($element['requireIndexes'])) { - $class->setRequireIndexes($element['requireIndexes']); - } if (isset($element['slaveOkay'])) { $class->setSlaveOkay($element['slaveOkay']); } diff --git a/lib/Doctrine/ODM/MongoDB/MongoDBException.php b/lib/Doctrine/ODM/MongoDB/MongoDBException.php index 4415779746..db351fd82f 100644 --- a/lib/Doctrine/ODM/MongoDB/MongoDBException.php +++ b/lib/Doctrine/ODM/MongoDB/MongoDBException.php @@ -98,19 +98,6 @@ public static function cannotPersistMappedSuperclass($className) return new self('Cannot persist an embedded document or mapped superclass ' . $className); } - /** - * @param string $className - * @param string $unindexedFields - * @return MongoDBException - */ - public static function queryNotIndexed($className, $unindexedFields) - { - return new self(sprintf('Cannot execute unindexed queries on %s. Unindexed fields: %s', - $className, - implode(', ', $unindexedFields) - )); - } - /** * @param string $className * @return MongoDBException diff --git a/lib/Doctrine/ODM/MongoDB/Query/Builder.php b/lib/Doctrine/ODM/MongoDB/Query/Builder.php index e0b6bb39e4..92df1dfaac 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Builder.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Builder.php @@ -73,13 +73,6 @@ class Builder extends \Doctrine\MongoDB\Query\Builder */ private $primers = array(); - /** - * Whether or not to require indexes. - * - * @var bool - */ - private $requireIndexes; - /** * Whether or not to register documents in UnitOfWork. * @@ -102,18 +95,6 @@ public function __construct(DocumentManager $dm, $documentName = null) } } - /** - * Set whether or not to require indexes. - * - * @param bool $requireIndexes - * @return $this - */ - public function requireIndexes($requireIndexes = true) - { - $this->requireIndexes = $requireIndexes; - return $this; - } - /** * Set the current field to operate on. * @@ -375,7 +356,6 @@ public function getQuery(array $options = array()) $this->hydrate, $this->refresh, $this->primers, - $this->requireIndexes, $this->readOnly ); } diff --git a/lib/Doctrine/ODM/MongoDB/Query/FieldExtractor.php b/lib/Doctrine/ODM/MongoDB/Query/FieldExtractor.php deleted file mode 100644 index 38c4c2f46a..0000000000 --- a/lib/Doctrine/ODM/MongoDB/Query/FieldExtractor.php +++ /dev/null @@ -1,94 +0,0 @@ -. - */ - -namespace Doctrine\ODM\MongoDB\Query; - -/** - * Class responsible for extracting an array of field names that are involved in - * a given mongodb query. Used for checking if query is indexed. - * - * @see Doctrine\ODM\MongoDB\Query::isIndexed() - */ -class FieldExtractor -{ - private $query; - private $sort; - - public function __construct(array $query, array $sort = array()) - { - $this->query = $query; - $this->sort = $sort; - } - - public function getFields() - { - $fields = array(); - - foreach ($this->query as $k => $v) { - if (is_array($v) && isset($v['$elemMatch']) && is_array($v['$elemMatch'])) { - $elemMatchFields = $this->getFieldsFromElemMatch($v['$elemMatch']); - foreach ($elemMatchFields as $field) { - $fields[] = $k.'.'.$field; - } - } elseif ($this->isOperator($k, array('and', 'or'))) { - foreach ($v as $q) { - $test = new self($q); - $fields = array_merge($fields, $test->getFields()); - } - } elseif ($k[0] !== '$') { - $fields[] = $k; - } - } - $fields = array_unique(array_merge($fields, array_keys($this->sort))); - return $fields; - } - - private function getFieldsFromElemMatch(array $elemMatch) - { - $fields = array(); - foreach ($elemMatch as $fieldName => $value) { - if ($this->isOperator($fieldName, 'where')) { - continue; - } - - if ($this->isOperator($fieldName, array('and', 'or'))) { - foreach ($value as $q) { - $test = new self($q); - $fields = array_merge($fields, $test->getFields()); - } - } else { - $fields[] = $fieldName; - } - } - return $fields; - } - - private function isOperator($fieldName, $operator) - { - if ( ! is_array($operator)) { - $operator = array($operator); - } - foreach ($operator as $op) { - if ($fieldName === '$' . $op) { - return true; - } - } - return false; - } -} diff --git a/lib/Doctrine/ODM/MongoDB/Query/Query.php b/lib/Doctrine/ODM/MongoDB/Query/Query.php index 21e99d9be9..1490e8517b 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Query.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Query.php @@ -70,13 +70,6 @@ class Query extends \Doctrine\MongoDB\Query\Query */ private $primers = array(); - /** - * Whether or not to require indexes. - * - * @var boolean - */ - private $requireIndexes; - /** * Hints for UnitOfWork behavior. * @@ -95,10 +88,9 @@ class Query extends \Doctrine\MongoDB\Query\Query * @param boolean $hydrate * @param boolean $refresh * @param array $primers - * @param null $requireIndexes * @param boolean $readOnly */ - public function __construct(DocumentManager $dm, ClassMetadata $class, Collection $collection, array $query = array(), array $options = array(), $hydrate = true, $refresh = false, array $primers = array(), $requireIndexes = null, $readOnly = false) + public function __construct(DocumentManager $dm, ClassMetadata $class, Collection $collection, array $query = array(), array $options = array(), $hydrate = true, $refresh = false, array $primers = array(), $readOnly = false) { $primers = array_filter($primers); @@ -115,7 +107,6 @@ public function __construct(DocumentManager $dm, ClassMetadata $class, Collectio $this->class = $class; $this->hydrate = $hydrate; $this->primers = $primers; - $this->requireIndexes = $requireIndexes; $this->setReadOnly($readOnly); $this->setRefresh($refresh); @@ -186,53 +177,6 @@ public function setRefresh($refresh) $this->unitOfWorkHints[Query::HINT_REFRESH] = (boolean) $refresh; } - /** - * Gets the fields involved in this query. - * - * @return array $fields An array of fields names used in this query. - */ - public function getFieldsInQuery() - { - $query = isset($this->query['query']) ? $this->query['query'] : array(); - $sort = isset($this->query['sort']) ? $this->query['sort'] : array(); - - $extractor = new FieldExtractor($query, $sort); - return $extractor->getFields(); - } - - /** - * Check if this query is indexed. - * - * @return bool - */ - public function isIndexed() - { - $fields = $this->getFieldsInQuery(); - foreach ($fields as $field) { - if ( ! $this->collection->isFieldIndexed($field)) { - return false; - } - } - return true; - } - - /** - * Gets an array of the unindexed fields in this query. - * - * @return array - */ - public function getUnindexedFields() - { - $unindexedFields = array(); - $fields = $this->getFieldsInQuery(); - foreach ($fields as $field) { - if ( ! $this->collection->isFieldIndexed($field)) { - $unindexedFields[] = $field; - } - } - return $unindexedFields; - } - /** * Execute the query and returns the results. * @@ -241,10 +185,6 @@ public function getUnindexedFields() */ public function execute() { - if ($this->isIndexRequired() && ! $this->isIndexed()) { - throw MongoDBException::queryNotIndexed($this->class->name, $this->getUnindexedFields()); - } - $results = parent::execute(); if ( ! $this->hydrate) { @@ -322,14 +262,4 @@ protected function prepareCursor(BaseCursor $cursor) return $cursor; } - - /** - * Return whether queries on this document should require indexes. - * - * @return boolean - */ - private function isIndexRequired() - { - return $this->requireIndexes !== null ? $this->requireIndexes : $this->class->requireIndexes; - } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/GeoSpatialTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/GeoSpatialTest.php index 2c6f648bb0..e025bab185 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/GeoSpatialTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/GeoSpatialTest.php @@ -21,14 +21,6 @@ public function testQueries() ), $qb->getQueryArray()); } - public function testGetFieldsInCoordinatesQuery() - { - $qb = $this->dm->createQueryBuilder(__NAMESPACE__.'\City'); - $qb->field('coordinates')->withinBox(41, 41, 72, 72); - $query = $qb->getQuery(); - $this->assertEquals(array('coordinates'), $query->getFieldsInQuery()); - } - public function testGeoSpatial1() { $this->dm->getSchemaManager()->ensureDocumentIndexes(__NAMESPACE__.'\City'); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/RequireIndexesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/RequireIndexesTest.php deleted file mode 100644 index 98c864c595..0000000000 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/RequireIndexesTest.php +++ /dev/null @@ -1,321 +0,0 @@ -dm->getSchemaManager()->ensureDocumentIndexes('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - } - - public function testGetFieldsInQueryWithSimpleEquals() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->field('test')->equals('test'); - $query = $qb->getQuery(); - $this->assertEquals(array('test'), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryIgnoresWhereOperator() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->where('this.test > 0'); - $qb->addOr($qb->expr()->where('this.ok > 1')); - $qb->addAnd($qb->expr()->field('username')->equals('jwage')); - $query = $qb->getQuery(); - $this->assertEquals(array('username'), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryWithElemMatch() - { - $date = new \DateTime(); - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->field('flashes')->elemMatch( - $qb->expr()->field('startDate')->lt($date)->field('endDate')->gte($date) - ); - $query = $qb->getQuery(); - $this->assertEquals(array( - 'flashes.startDate', - 'flashes.endDate' - ), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryWithElemMatchAndOr() - { - $date = new \DateTime(); - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->field('flashes')->elemMatch( - $qb->expr()->field('startDate')->lt($date)->field('endDate')->gte($date)->field('startDate') - ->addOr($qb->expr()->field('something')->equals($date)) - - ->where('this.id > 0') - )->addAnd($qb->expr()->field('flashes.id')->equals('foo')); - $query = $qb->getQuery(); - $this->assertEquals(array( - 'flashes.startDate', - 'flashes.endDate', - 'flashes.something', - 'flashes.id' - ), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryWithOrAndIn() - { - $date = new \DateTime(); - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->addOr($qb->expr()->field('field1')->in(array(1))); - $qb->addOr($qb->expr()->field('field2')->in(array(1))); - $query = $qb->getQuery(); - $this->assertEquals(array('field1', 'field2'), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryWithComplexQuery() - { - $date = new \DateTime(); - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->addOr($qb->expr()->field('field1')->in(array(1))); - $qb->addAnd($qb->expr()->field('field2')->equals(1)); - $qb->field('field3')->elemMatch($qb->expr()->field('embedded')->range(1, 2)); - $qb->field('field4')->elemMatch($qb->expr()->addOr($qb->expr()->field('embedded')->equals($date))); - $qb->field('field5')->equals('test'); - $query = $qb->getQuery(); - $this->assertEquals(array( - 'field1', - 'field2', - 'field3.embedded', - 'field4.embedded', - 'field5' - ), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryWithIn() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->field('test')->in(array(1)); - $query = $qb->getQuery(); - $this->assertEquals(array('test'), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryWithNotIn() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->field('test')->notIn(array(1)); - $query = $qb->getQuery(); - $this->assertEquals(array('test'), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryWithNotEqual() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->field('test')->notEqual(1); - $query = $qb->getQuery(); - $this->assertEquals(array('test'), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryWithNot() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->field('test')->not(1); - $query = $qb->getQuery(); - $this->assertEquals(array('test'), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryWithReferences() - { - $reference = new DoesNotRequireIndexesDocument(); - $reference->id = (string) new \MongoId(); - $this->dm->persist($reference); - - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->field('reference')->references($reference); - $qb->field('simpleReference')->references($reference); - $query = $qb->getQuery(); - $this->assertEquals(array('reference.$id', 'simpleReference'), $query->getFieldsInQuery()); - } - - public function testGetFieldsInQueryWithIncludesReferences() - { - $reference = new DoesNotRequireIndexesDocument(); - $reference->id = (string) new \MongoId(); - $this->dm->persist($reference); - - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument'); - $qb->field('reference')->includesReferenceTo($reference); - $qb->field('simpleReference')->includesReferenceTo($reference); - $query = $qb->getQuery(); - $this->assertEquals(array('reference.$id', 'simpleReference'), $query->getFieldsInQuery()); - } - - public function testIsIndexedTrue() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument') - ->field('indexed')->equals('test'); - $query = $qb->getQuery(); - $this->assertTrue($query->isIndexed()); - } - - public function testIsIndexedFalse() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument') - ->field('notIndexed')->equals('test'); - $query = $qb->getQuery(); - $this->assertFalse($query->isIndexed()); - - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument') - ->field('indexed')->equals('test') - ->field('notIndexed')->equals('test'); - $query = $qb->getQuery(); - $this->assertFalse($query->isIndexed()); - } - - /** - * @expectedException Doctrine\ODM\MongoDB\MongoDBException - */ - public function testRequireIndexesThrowsExceptionOnExecute() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument') - ->field('notIndexed')->equals('test'); - $query = $qb->getQuery(); - $query->execute(); - } - - public function testRequireIndexesExceptionMessage() - { - try { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument') - ->field('notIndexed')->equals('test'); - $query = $qb->getQuery(); - $query->execute(); - } catch (MongoDBException $e) { - $this->assertEquals('Cannot execute unindexed queries on Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument. Unindexed fields: notIndexed', $e->getMessage()); - } - } - - /** - * @expectedException Doctrine\ODM\MongoDB\MongoDBException - */ - public function testForceEnableRequireIndexes() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\DoesNotRequireIndexesDocument') - ->field('notIndexed')->equals('test') - ->requireIndexes(); - $query = $qb->getQuery(); - $query->execute(); - } - - public function testForceDisableRequireIndexes() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument') - ->field('notIndexed')->equals('test') - ->requireIndexes(false); - $query = $qb->getQuery(); - $query->execute(); - } - - - public function testRequireIndexesFalse() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\DoesNotRequireIndexesDocument') - ->field('notIndexed')->equals('test'); - $query = $qb->getQuery(); - $query->execute(); - } - - public function testRequireIndexesOnEmbeddedDocument() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument') - ->field('embedOne.indexed')->equals('test'); - $query = $qb->getQuery(); - $query->execute(); - } - - /** - * @expectedException Doctrine\ODM\MongoDB\MongoDBException - */ - public function testRequireIndexesOnEmbeddedDocumentThrowsException() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument') - ->field('embedOne.notIndexed')->equals('test'); - $query = $qb->getQuery(); - $query->execute(); - } - - /** - * @expectedException Doctrine\ODM\MongoDB\MongoDBException - */ - public function testRequireIndexesOnSortThrowException() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument') - ->sort('embedOne.notIndexed', 'asc'); - $query = $qb->getQuery(); - $query->execute(); - } - - public function testGetUnindexedFields() - { - $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument') - ->field('embedOne.notIndexed')->equals('test') - ->field('notIndexed')->equals('test') - ->field('indexed')->equals('test'); - $query = $qb->getQuery(); - $this->assertEquals(array('embedOne.notIndexed', 'notIndexed'), $query->getUnindexedFields()); - } -} - -/** - * @ODM\Document(requireIndexes=true) - */ -class RequireIndexesDocument -{ - /** @ODM\Id */ - public $id; - - /** @ODM\Field(type="string") @ODM\Index */ - public $indexed; - - /** @ODM\Field(type="string") */ - public $notIndexed; - - /** @ODM\EmbedOne(targetDocument="Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesEmbeddedDocument") */ - public $embedOne; - - /** @ODM\EmbedMany(targetDocument="Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesEmbeddedDocument") */ - public $embedMany; - - /** @ODM\ReferenceOne(targetDocument="Doctrine\ODM\MongoDB\Tests\Functional\DoesNotRequireIndexesDocument") */ - public $reference; - - /** @ODM\ReferenceOne(targetDocument="Doctrine\ODM\MongoDB\Tests\Functional\DoesNotRequireIndexesDocument", simple=true) */ - public $simpleReference; -} - -/** - * @ODM\Document(requireIndexes=false) - */ -class DoesNotRequireIndexesDocument -{ - /** @ODM\Id */ - public $id; - - /** @ODM\Field(type="string") @ODM\Index */ - public $indexed; - - /** @ODM\Field(type="string") */ - public $notIndexed; -} - -/** @ODM\EmbeddedDocument */ -class RequireIndexesEmbeddedDocument -{ - /** @ODM\Field(type="string") @ODM\Index */ - public $indexed; - - /** @ODM\Field(type="string") */ - public $notIndexed; -} diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php index 7453e77dee..aa1ab5f7fc 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php @@ -43,7 +43,6 @@ public function testDriverShouldParseNonStringAttributes() $classMetadata = new ClassMetadata('TestDocuments\UserNonStringOptions'); $this->driver->loadMetadataForClass('TestDocuments\UserNonStringOptions', $classMetadata); - $this->assertSame(true, $classMetadata->requireIndexes); $this->assertSame(false, $classMetadata->slaveOkay); $profileMapping = $classMetadata->fieldMappings['profile']; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/xml/TestDocuments.UserNonStringOptions.dcm.xml b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/xml/TestDocuments.UserNonStringOptions.dcm.xml index 8a3df80da4..eb8f43185f 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/xml/TestDocuments.UserNonStringOptions.dcm.xml +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/xml/TestDocuments.UserNonStringOptions.dcm.xml @@ -1,13 +1,13 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Query/FieldExtractorTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Query/FieldExtractorTest.php deleted file mode 100644 index f57629aadd..0000000000 --- a/tests/Doctrine/ODM/MongoDB/Tests/Query/FieldExtractorTest.php +++ /dev/null @@ -1,88 +0,0 @@ -assertFieldsExtracted($query, $fields); - } - - public function getQueriesAndFields() - { - return array( - array( - array('fieldName' => 1), - array('fieldName') - ), - array( - array('fieldName' => array( - '$elemMatch' => array( - 'embedded' => 1 - ) - )), - array('fieldName.embedded') - ), - array( - array('fieldName' => array( - '$in' => array(1) - )), - array('fieldName') - ), - array( - array('fieldName' => array( - '$gt' => 1 - )), - array('fieldName') - ), - array( - array('$or' => array( - array( - 'fieldName1' => array( - '$in' => array(1) - ) - ), - array( - 'fieldName2' => array( - '$in' => array(1) - ) - ), - array( - 'fieldName3' => 1 - ) - )), - array('fieldName1', 'fieldName2', 'fieldName3') - ), - array( - array('$and' => array( - array( - 'fieldName1' => array( - '$in' => array(1) - ) - ), - array( - 'fieldName2' => array( - '$in' => array(1) - ) - ), - array( - 'fieldName3' => 1 - ) - )), - array('fieldName1', 'fieldName2', 'fieldName3') - ) - ); - } - - private function assertFieldsExtracted(array $query, array $fields) - { - $extractor = new FieldExtractor($query); - $this->assertEquals($fields, $extractor->getFields()); - } -} \ No newline at end of file