public function testSomeFunctions() { $test = new Article(); $wrapped = new MongoDocumentWrapper($test, $this->dm); $wrapped->populate(array('title' => 'test')); $this->assertEquals('test', $wrapped->getPropertyValue('title')); $this->assertFalse($wrapped->hasValidIdentifier()); }
/** * {@inheritDoc} */ public function getChildrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'asc', $includeNode = false) { $meta = $this->getClassMetadata(); $config = $this->listener->getConfiguration($this->dm, $meta->name); $separator = preg_quote($config['path_separator']); $qb = $this->dm->createQueryBuilder()->find($meta->name); $regex = false; if (is_object($node) && $node instanceof $meta->name) { $node = new MongoDocumentWrapper($node, $this->dm); $nodePath = preg_quote($node->getPropertyValue($config['path'])); if ($direct) { $regex = sprintf('/^%s([^%s]+%s)' . ($includeNode ? '?' : '') . '$/', $nodePath, $separator, $separator); } else { $regex = sprintf('/^%s(.+)' . ($includeNode ? '?' : '') . '/', $nodePath); } } elseif ($direct) { $regex = sprintf('/^([^%s]+)' . ($includeNode ? '?' : '') . '%s$/', $separator, $separator); } if ($regex) { $qb->field($config['path'])->equals(new \MongoRegex($regex)); } $qb->sort(null === $sortByField ? $config['path'] : $sortByField, $direction === 'asc' ? 'asc' : 'desc'); return $qb; }