public function testEventArgsNamespaceTest() { $listener = new ListenerStub(); $manager = new EventManager(); $manager->addEventListener(\Doctrine\MongoDB\Events::preConnect, $listener); $connection = new Connection(null, [], null, $manager); $connection->initialize(); }
public function setUp() { $yaml = new Parser(); $this->parametersFromYmlFile = $yaml->parse(file_get_contents(__DIR__ . '/parameters.yml'))['parameters']; $config = new Configuration(); $conn = new Connection($this->parametersFromYmlFile['mongodb_server'], [], $config); $this->db = $conn->selectDatabase($this->parametersFromYmlFile['mongodb_db']); $this->wipeDatabase(); }
/** * Constructor * * @param \Doctrine\MongoDb\Connection $connection * @param string $database * @param PermissionGrantingStrategyInterface $permissionGrantingStrategy * @param array $options * @param AclCacheInterface $aclCache */ public function __construct(Connection $connection, $database, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $options, AclCacheInterface $aclCache = null) { $this->aclCache = $aclCache; $this->connection = $connection->selectDatabase($database); $this->loadedAces = array(); $this->loadedAcls = array(); $this->options = $options; $this->permissionGrantingStrategy = $permissionGrantingStrategy; }
public function testLog() { $conn = new Connection(); $called = false; $conn->getConfiguration()->setLoggerCallable(function ($msg) use(&$called) { $called = $msg; }); $conn->log(array('test')); $this->assertEquals(array('test'), $called); }
protected function setUp() { // comment the following line, and run only this test, if you need to benchmark $this->markTestSkipped('Benchmarking skipped'); if (!class_exists('Doctrine\\MongoDB\\Connection')) { $this->markTestSkipped('Doctrine2 MongoDB is required for this test'); } $database = 'aclBenchmark'; $mongo = new \Doctrine\MongoDB\Connection(); $this->con = $mongo->selectDatabase($database); $this->options = $this->getOptions(); }
public function testDriverOptions() { if (!extension_loaded('mongo')) { $this->markTestSkipped('Test will not work with polyfills for ext-mongo'); } $callCount = 0; $streamContext = stream_context_create(['mongodb' => ['log_cmd_delete' => function () use(&$callCount) { $callCount++; }]]); $connection = new Connection(null, [], null, null, ['context' => $streamContext]); $connection->selectCollection('test', 'collection')->remove([]); $this->assertSame(1, $callCount); }
protected function setUp() { $connection = new Connection(); $eventStoreOptions = new DoctrineMongoDBStorageOptions('palya-test-events'); $snapshotStorageOptions = new DoctrineMongoDBStorageOptions('palya-test-snapshots'); // set up a clean state by deleting the database $connection->dropDatabase($eventStoreOptions->getDatabase()); $connection->dropDatabase($snapshotStorageOptions->getDatabase()); $serializer = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $registry) { $registry->registerSubscribingHandler(new UuidHandler()); })->build(); $this->eventStore = new EventStore(new DoctrineMongoDBEventStorage($connection, $eventStoreOptions, $serializer), new NullBus(), new InMemoryIdentityMap()); $snapshotStorage = new DoctrineMongoDBSnapshotStorage($connection, $eventStoreOptions, $serializer); $this->customerRepository = new CustomerRepository($this->eventStore); $this->customerSnapshotRepository = new CustomerSnapshotRepository($this->eventStore, $snapshotStorage); }
/** * @return Doctrine\MongoDB\Connection */ public function getDatabase() { if (isset($this->database)) { return $this->database; } $this->database = $this->connection->selectDatabase($this->migrationsDatabaseName); return $this->database; }
/** * Returns the MongoDB instance for a class. * * @param string $className The class name. * @return Doctrine\MongoDB\Database */ public function getDocumentDatabase($className) { $metadata = $this->metadataFactory->getMetadataFor($className); $db = $metadata->getDatabase(); $db = $db ? $db : $this->config->getDefaultDB(); $db = $db ? $db : 'doctrine'; $db = sprintf('%s%s', $this->config->getEnvironmentPrefix(), $db); $database = $this->connection->selectDatabase($db); return $database; }
protected function tearDown() { $this->oid = array(); if ($this->connection) { $this->connection->close(); $this->connection = null; } if ($this->con) { $this->con->drop(); $this->con = null; } }
/** * Returns the MongoDB instance for a class. * * @param string $className The class name. * @return \Doctrine\MongoDB\Database */ public function getDocumentDatabase($className) { if (isset($this->documentDatabases[$className])) { return $this->documentDatabases[$className]; } $metadata = $this->metadataFactory->getMetadataFor($className); $db = $metadata->getDatabase(); $db = $db ? $db : $this->config->getDefaultDB(); $db = $db ? $db : 'doctrine'; $this->documentDatabases[$className] = $this->connection->selectDatabase($db); return $this->documentDatabases[$className]; }
/** * @expectedException InvalidArgumentException */ public function testSetMongoShouldThrowExceptionForInvalidArgument() { $mongoDB = $this->getMockBuilder('MongoDB')->disableOriginalConstructor()->getMock(); $conn = new Connection(); $conn->setMongo($mongoDB); }
/** * @return \MongoDB */ protected function getMongoDatabase() { $dbName = $this->container->getParameter('mongodb_database'); return $this->mongoConnection->getMongoClient()->{$dbName}; }
/** * Gets the MongoDB Collection object for a Model. * * @param EntityMetadata $metadata * @return \Doctrine\MongoDB\Collection */ protected function getModelCollection(EntityMetadata $metadata) { return $this->connection->selectCollection($metadata->persistence->db, $metadata->persistence->collection); }
/** * Return whether this datasource is connected or not to the persistent storage server * * @return boolean */ public function isConnected() { return $this->connection->isConnected(); }
/** * @param Name $name * @return \Doctrine\MongoDB\Database */ public function getDatabaseForTestingMigration(Name $name) { $connection = new Connection($this->configuration->getDatabaseServerUri(), [], new DoctrineConfiguration()); return $connection->selectDatabase('mongrate_test_' . $name); }
public function selectDatabase($name) { $name = $this->getDbNameFromEnv($name); return parent::selectDatabase($name); }
public function testConnectTimeoutOptionIsConverted() { /* Since initialize() creates MongoClient directly, we cannot examine * the options passed to its constructor. * * Note: we do not test "wTimeout" conversion, since the driver does not * raise a deprecation notice for its usage (see: PHP-1079). */ $conn = new Connection(null, ['timeout' => 10000]); $conn->initialize(); }
/** * Constructor/DI. * * @param string $dbName */ public function __construct($dbName) { $connection = new Connection('mongodb://localhost:27017'); $this->collection = $connection->selectCollection($dbName, 'Todo'); }
public function testConnectTimeoutOptionIsConverted() { if (version_compare(phpversion('mongo'), '1.4.0', '<')) { $this->markTestSkipped('This test is not applicable to driver versions < 1.4.0'); } /* Since initialize() creates MongoClient directly, we cannot examine * the options passed to its constructor. * * Note: we do not test "wTimeout" conversion, since the driver does not * raise a deprecation notice for its usage (see: PHP-1079). */ $conn = new Connection(null, array('timeout' => 10000)); $conn->initialize(); }
protected function setUp() { if (!class_exists('Doctrine\\MongoDB\\Connection')) { $this->markTestSkipped('Doctrine2 MongoDB is required for this test'); } $database = 'aclTest'; $this->connection = $mongo = new \Doctrine\MongoDB\Connection(); $this->con = $mongo->selectDatabase($database); $options = $this->getOptions(); // populate the db with some test data $fields = array('classType'); $classes = array(); foreach ($this->getClassData() as $data) { $id = array_shift($data); $query = array_combine($fields, $data); $classes[$id] = $query; } $fields = array('identifier', 'username'); $sids = array(); foreach ($this->getSidData() as $data) { $id = array_shift($data); $sids[$id] = $data; } $this->oidCollection = $this->con->selectCollection($options['oid_collection']); $this->oids = array(); foreach ($this->getOidData() as $data) { $query = array(); $id = $data[0]; $classId = $data[1]; $query['identifier'] = $data[2]; $query['type'] = $classes[$classId]['classType']; $parentId = $data[3]; if ($parentId) { $parent = $this->oids[$parentId]; if (isset($parent['ancestors'])) { $ancestors = $parent['ancestors']; } $ancestors[] = $parent['_id']; $query['ancestors'] = $ancestors; $query['parent'] = $parent; } $query['entriesInheriting'] = $data[4]; $this->oidCollection->insert($query); $this->oids[$id] = $query; } $fields = array('id', 'class', 'objectIdentity', 'fieldName', 'aceOrder', 'securityIdentity', 'mask', 'granting', 'grantingStrategy', 'auditSuccess', 'auditFailure'); $this->entryCollection = $this->con->selectCollection($options['entry_collection']); foreach ($this->getEntryData() as $data) { $query = array_combine($fields, $data); unset($query['id']); unset($query['class']); $oid = $query['objectIdentity']; $query['objectIdentity'] = array('$ref' => $options['oid_collection'], '$id' => $this->oids[$oid]['_id']); $sid = $query['securityIdentity']; if ($sid) { $query['securityIdentity'] = $sids[$sid]; } $this->entryCollection->insert($query); } }