Exemplo n.º 1
0
 /**
  * Test that calling MapDoc produces the correct output
  * 
  * @dataProvider documentProvider 
  * @param string $docStr
  */
 public function testMapDoc($docStr)
 {
     $funcs = array('function($doc){ $a = 1 + 2; }', 'function($doc){ $view->emit($doc->_id, $doc->title); }', 'function($doc){ if ($doc->type == "Page") { $view->emit(array($doc->_id, $doc->title), $doc->content); $view->log("Some message!");}}');
     // Prepare input stream
     $inputStr = '';
     foreach ($funcs as $fText) {
         $inputStr .= json_encode(array('add_fun', $fText)) . "\n";
     }
     $inStream = 'data://text/plain;base64,' . base64_encode($inputStr);
     $this->_server->run($inStream);
     $this->assertEquals(3, count($this->getObjectAttribute($this->_server, '_functions')));
     $inputStr = json_encode(array('map_doc', $docStr)) . "\n";
     $inStream = 'data://text/plain;base64,' . base64_encode($inputStr);
     $this->_server->run($inStream);
     // Assert something here!
 }
Exemplo n.º 2
0
<?php

/**
 * Sopha CouchDB View Server
 * 
 * Hook this view server into CouchDB by adding the following line to CouchDB's
 * local.ini file:
 * 
 * [query_servers]
 * php=/path/to/php /path/to/this/file
 * 
 */
// Add the Sopha library to include path if it is available
$lib_path = realpath(dirname(dirname(__FILE__)) . '/library/Sopha');
if (is_dir($lib_path)) {
    set_include_path(dirname($lib_path) . PATH_SEPARATOR . get_include_path());
}
require_once 'Sopha/ViewServer.php';
$server = new Sopha_ViewServer();
$server->run();