/** * Setup a CouchDB HTTP connector * * @return void * @author Christopher Hlubek <*****@*****.**> */ public function setUp() { $this->client = $this->getAccessibleMock('TYPO3\\CouchDB\\Client', array('dummy'), array('http://127.0.0.1:5984')); $this->client->initializeObject(); if ($this->client->databaseExists($this->databaseName)) { $this->client->deleteDatabase($this->databaseName); } $this->client->createDatabase($this->databaseName); $this->client->setDatabaseName($this->databaseName); }
/** * Setup a CouchDB HTTP connector * * @return void * @author Christopher Hlubek <*****@*****.**> */ public function setUp() { $this->client = $this->getAccessibleMock('TYPO3\\CouchDB\\Client', array('dummy'), array('http://127.0.0.1:5984')); try { $this->client->initializeObject(); if ($this->client->databaseExists($this->databaseName)) { $this->client->deleteDatabase($this->databaseName); } } catch (\RuntimeException $e) { $this->markTestSkipped('We skip the test as we can not connect to CouchDB Server'); } $this->client->createDatabase($this->databaseName); $this->client->setDatabaseName($this->databaseName); }
/** * @test * @author Christopher Hlubek <*****@*****.**> */ public function viewGetsCreatedIfDatabaseExists() { $this->client->createDatabase($this->databaseName); $this->backend->append('Test entry', LOG_WARNING); $logs = $this->backend->read(0, 100, LOG_WARNING); $this->assertEquals(1, count($logs)); }
/** * Do a CouchDB operation and handle error conversion and creation of * the database on the fly. * * @param \Closure $couchDbOperation * @return mixed */ protected function doOperation(\Closure $couchDbOperation) { try { return $couchDbOperation($this->client); } catch (Client\ClientException $clientException) { $information = $clientException->getInformation(); if (isset($information['error']) && $information['error'] === 'not_found' && $information['reason'] === 'no_db_file') { if ($this->client->createDatabase($this->databaseName)) { return $this->doOperation($couchDbOperation); } else { throw new \TYPO3\Flow\Persistence\Exception('Could not create database ' . $this->database, 1286901880); } } else { throw $clientException; } } }
/** * @throws \TYPO3\CouchDB\Client\NotFoundException * @return void */ public function synchronize() { try { $designDocument = $this->client->getDocument('_design/' . $this->getDesignDocumentName(), array('decodeAssociativeArray' => TRUE)); } catch (\TYPO3\CouchDB\Client\NotFoundException $notFoundException) { $information = $notFoundException->getInformation(); if ($information['reason'] === 'no_db_file') { $this->client->createDatabase(); } if ($information['reason'] === 'no_db_file' || $information['reason'] === 'missing') { $designDocument = array('_id' => '_design/' . $this->getDesignDocumentName(), 'language' => $this->language); } else { throw $notFoundException; } } $declarations = $this->getDeclarations(); foreach ($declarations as $declaration) { $viewDeclaration = call_user_func(get_class($this) . '::' . $declaration . 'Declaration'); $designDocument['views'][$declaration] = $viewDeclaration; } $this->client->createDocument($designDocument); }
/** * Initializes an empty database and setup the needed view code to * query for log messages * * @return void * @author Christopher Hlubek <*****@*****.**> */ protected function initializeDatabase() { if (!$this->client->databaseExists($this->databaseName)) { $this->client->createDatabase($this->databaseName); } }