public function tearDown()
 {
     // Remove / clear test database
     $db = phpillowConnection::getInstance();
     try {
         $db->delete('/test');
     } catch (phpillowResponseNotFoundErrorException $e) {
         /* Ignore */
     }
     phpillowConnectionTestHelper::reset();
 }
 public function testOverwriteAttachment()
 {
     $db = phpillowConnection::getInstance();
     $doc = phpillowUserDocument::createNew();
     $doc->login = '******';
     $doc->attachFile(dirname(__FILE__) . '/data/image_png.png');
     $doc->save();
     $doc = phpillowManager::fetchDocument('user', 'user-kore');
     $doc->attachFile($file = dirname(__FILE__) . '/data/image_jpg.jpg', 'image_png.png');
     $doc->save();
     $doc = phpillowManager::fetchDocument('user', 'user-kore');
     $response = $doc->getFile('image_png.png');
     $this->assertSame(file_get_contents($file), $response->data);
     $this->assertSame('application/octet-stream', $response->contentType);
 }
 /**
  * Reset database depending on provided options
  *
  * @param array $options
  * @return void
  */
 public static function resetDatabase(array $options = array())
 {
     phpillowConnectionTestHelper::reset();
     // Initialize wanted connection handler
     $handler = isset($options['handler']) ? $options['handler'] : 'phpillowConnection';
     call_user_func(array($handler, 'createInstance'));
     $db = phpillowConnection::getInstance();
     try {
         $db->delete('/test');
     } catch (Exception $e) {
         /* Ignored */
     }
     if (isset($options['database'])) {
         // Create test database
         phpillowConnection::setDatabase($options['database']);
         $db = phpillowConnection::getInstance();
         $db->put('/' . $options['database']);
     } else {
         // Reset all connection settings in the end
         phpillowConnectionTestHelper::reset();
     }
 }
<?php

// Include all required classes
$autoload = (require ($base = dirname(__FILE__) . '/../src/') . 'classes/autoload.php');
foreach ($autoload as $file) {
    require_once $base . $file;
}
// Configure parameters for speed testing
$puts = 1000;
$gets = 5000;
$views = 2000;
// Set up backend connection
phpillowConnection::createInstance('10.0.118.171', 5984, 'admin', 'm4!1.d3');
phpillowConnection::setDatabase('test');
$db = phpillowConnection::getInstance();
try {
    $db->delete('/test');
} catch (Exception $e) {
    /* Ignore */
}
$db->put('/test');
// /*
$start = microtime(true);
for ($i = 0; $i < $puts; ++$i) {
    $doc = new phpillowUserDocument();
    $doc->login = '******' . $i;
    $doc->name = 'Kore Nordmann';
    $doc->save();
}
printf("%d PUTs in %.2fs (%d req/s)\n", $puts, $time = microtime(true) - $start, $puts / $time);
// */
Exemple #5
0
 /**
  * Query a view
  *
  * Query the specified view to get a set of results. You may optionally use
  * the view query options as additional parameters to limit the returns
  * values, specified at:
  * http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
  *
  * @param string $view
  * @param array $options
  * @return phpillowResultArray
  */
 public function query($view, array $options = array())
 {
     // Build query string, just as a normal HTTP GET query string
     $url = phpillowConnection::getDatabase() . '_design/' . $this->getViewName() . '/_view/' . $view;
     $url .= $this->buildViewQuery($options);
     // Get database connection, because we directly execute a query here.
     $db = phpillowConnection::getInstance();
     try {
         // Try to execute query, a failure most probably means, the view
         // has not been added, yet.
         $response = $db->get($url);
     } catch (phpillowResponseErrorException $e) {
         // Ensure view has been created properly and then try to execute
         // the query again. If it still fails, there is most probably a
         // real problem.
         $this->verifyView();
         $response = $db->get($url);
     }
     return $response;
 }
 function couchDelete($id, $rev)
 {
     //		phpillowConnection::__call("delete","");
     $db = phpillowConnection::getInstance();
     $response = $db->__call("delete", array(0 => phpillowConnection::getDatabase() . urlencode($id) . "?rev=" . $rev));
 }
 public function testDeleteDocumentMultipleRevisions()
 {
     phpillowConnection::createInstance();
     phpillowConnection::setDatabase('test');
     // Create test database
     $db = phpillowConnection::getInstance();
     $db->put('/test');
     // Add document to fetch
     $author = phpillowManager::createDocument('user');
     $author->login = '******';
     $author->save();
     $doc = phpillowManager::fetchDocument('user', 'user-kore');
     $doc->name = 'Kore';
     $doc->save();
     // Test delete
     phpillowManager::deleteDocument('user', 'user-kore');
     try {
         $user = phpillowManager::fetchDocument('user', 'user-kore');
         $this->fail('Expected phpillowResponseNotFoundErrorException.');
     } catch (phpillowResponseNotFoundErrorException $e) {
         /* Expected exception */
     }
     // Remove / clear test database
     $db = phpillowConnection::getInstance();
     $db->delete('/test');
     phpillowConnectionTestHelper::reset();
 }
Exemple #8
0
 /**
  * Delete document by ID
  *
  * Delete the document of the given type with the given ID. Throws a
  * phpillowNoSuchPropertyException if the document does not exist.
  *
  * Deletion means, that all revisions, including the current one, are
  * removed.
  * 
  * @param string $name 
  * @param string $id 
  * @return void
  */
 public static function deleteDocument($name, $id)
 {
     // Check if a document with the given name exists.
     if (!isset(self::$documents[$name])) {
         throw new phpillowNoSuchPropertyException($name);
     }
     $db = phpillowConnection::getInstance();
     $revision = $db->get($db->getDatabase() . $id);
     // Only delete the current revision. This should delete all revisions
     // in the database except somebody updates the document between the get
     // and the delete request
     $db->delete($db->getDatabase() . $id . '?rev=' . $revision->_rev);
 }
 public function testHttpLog()
 {
     phpillowTestEnvironmentSetup::resetDatabase(array('database' => 'test', 'handler' => 'phpillowStreamConnection'));
     $db = phpillowConnection::getInstance();
     $db->setOption('http-log', $logFile = tempnam(dirname(__FILE__) . '/../temp', __CLASS__));
     $response = $db->put('/test/123', '{"_id":"123","data":"Foo"}');
     $response = $db->get('/test/123');
     $this->assertTrue(filesize($logFile) > 128);
 }
Exemple #10
0
 /**
  * Get file contents
  *
  * Get the contents of an attached file as a phpillowDataResponse.
  * 
  * @param string $fileName 
  * @return phpillowDataResponse
  */
 public function getFile($fileName)
 {
     if (!isset($this->storage->_attachments[$fileName])) {
         throw new phpillowNoSuchPropertyException($fileName);
     }
     $db = phpillowConnection::getInstance();
     $response = $db->get(phpillowConnection::getDatabase() . urlencode($this->_id) . '/' . $fileName, null, true);
     return $response;
 }
 /**
  * Return used connection
  *
  * This should always used within a document instead of
  * phpillowConnection::getInstance()
  *
  * @return phpillowConnection
  */
 public function getConnection()
 {
     if ($this->connection === null) {
         return phpillowConnection::getInstance();
     }
     return $this->connection;
 }
 public function testInvalidPath()
 {
     phpillowCustomConnection::createInstance();
     $db = phpillowConnection::getInstance();
     try {
         $response = $db->get('irrelevant');
         $this->fail('Expected phpillowInvalidRequestException.');
     } catch (phpillowInvalidRequestException $e) {
         /* Expected exception */
     }
 }