Example #1
0
 /**
  * @test
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function getDocumentInformationWorks()
 {
     $response = $this->client->createDocument(array('name' => 'Bar'));
     $id = $response->getId();
     $information = $this->client->getDocumentInformation($id);
     $this->assertEquals($response->getRevision(), $information->getRevision());
 }
 /**
  * @test
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function callingViewReturnsResult()
 {
     $design = new Fixtures\Design\CompanyDesign();
     $design->setClient($this->client);
     $design->synchronize();
     for ($i = 0; $i < 10; $i++) {
         $this->client->createDocument(array('Type' => 'purchase', 'Customer' => '12345678', 'Amount' => 13.95 * ($i + 1)));
     }
     $result = $design->totalPurchasesAmount('12345678');
     $this->assertEquals(767.25, $result);
 }
 /**
  * Creates a document for the given message and other information in the
  * log database. If the database doesn't exist yet, it will be created.
  *
  * @param string $message The message to log
  * @param integer $severity One of the LOG_* constants
  * @param mixed $additionalData A variable containing more information about the event to be logged
  * @param string $packageKey Key of the package triggering the log (determined automatically if not specified)
  * @param string $className Name of the class triggering the log (determined automatically if not specified)
  * @param string $methodName Name of the method triggering the log (determined automatically if not specified)
  * @return void
  * @author Christopher Hlubek <*****@*****.**>
  * @api
  */
 public function append($message, $severity = LOG_INFO, $additionalData = NULL, $packageKey = NULL, $className = NULL, $methodName = NULL)
 {
     if ($severity > $this->severityThreshold) {
         return;
     }
     if ($this->client === NULL) {
         return;
     }
     $document = array('timestamp' => microtime(TRUE), 'date' => strftime('%Y-%m-%dT%H:%M:%S'), 'host' => gethostname(), 'processId' => function_exists('posix_getpid') ? posix_getpid() : '', 'ipAddress' => $this->logIpAddress === TRUE ? isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '' : '', 'message' => $message, 'severity' => $severity, 'severityLabel' => $this->severityLabels[$severity], 'additionalData' => $additionalData, 'packageKey' => $packageKey, 'className' => $className, 'methodName' => $methodName);
     try {
         $this->client->createDocument($document);
     } catch (\TYPO3\CouchDB\Client\NotFoundException $notFoundException) {
         $information = $notFoundException->getInformation();
         if ($information['reason'] === 'no_db_file' || $information['reason'] === 'missing') {
             $this->initializeDatabase();
             $this->client->createDocument($document);
             return;
         }
         throw $notFoundException;
     }
 }
 /**
  * @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);
 }