public function testGetDatabaseInfo() { $data = $this->couchClient->getDatabaseInfo($this->getTestDatabase()); $this->assertInternalType('array', $data); $this->assertArrayHasKey('db_name', $data); $this->assertEquals($this->getTestDatabase(), $data['db_name']); }
public function testGetDatabaseInfo() { $data = $this->couchClient->getDatabaseInfo($this->getTestDatabase()); $this->assertInternalType('array', $data); $this->assertArrayHasKey('db_name', $data); $this->assertEquals($this->getTestDatabase(), $data['db_name']); $notExistedDb = 'not_existed_db'; $this->setExpectedException('Doctrine\\CouchDB\\HTTP\\HTTPException', 'HTTP Error with status 404 occoured while requesting /' . $notExistedDb . '. Error: not_found no_db_file'); $this->couchClient->getDatabaseInfo($notExistedDb); }
/** * @return array * @throws HTTPException * @throws \Exception */ public function verifyPeers() { $sourceInfo = null; try { $sourceInfo = $this->source->getDatabaseInfo($this->source->getDatabase()); } catch (HTTPException $e) { throw new \Exception('Source not reachable.'); } $targetInfo = null; try { $targetInfo = $this->target->getDatabaseInfo($this->target->getDatabase()); } catch (HTTPException $e) { if ($e->getCode() == 404 && $this->task->getCreateTarget()) { $this->target->createDatabase($this->target->getDatabase()); $targetInfo = $this->target->getDatabaseInfo($this->target->getDatabase()); } else { throw new \Exception("Target database does not exist."); } } return array($sourceInfo, $targetInfo); }
/** * @param \Doctrine\CouchDB\CouchDBClient $client * @param string $database * @param bool $createIfNotFound * * @return bool Returns TRUE ONLY when the database existed before the call. * @throws \Doctrine\CouchDB\HTTP\HTTPException */ public static function databaseExists($client, $database = null, $createIfNotFound = true) { try { return $client->getDatabaseInfo($database ?: $client->getDatabase()); } catch (\Doctrine\CouchDB\HTTP\HTTPException $_ex) { if (static::NotFound != $_ex->getCode()) { throw $_ex; } if (true === $createIfNotFound) { $client->createDatabase($database ?: $client->getDatabase()); } } return false; }