Exemple #1
0
 /**
  * Tests connection get/set
  *
  * @assert       same
  *
  * @author       Simon Thulbourn <*****@*****.**>
  */
 public function testConnection()
 {
     $connection = $this->getMockBuilder('\\phpcouch\\connection\\Connection')->disableOriginalConstructor()->getMock();
     $record = new record\Record($connection);
     $this->assertSame($record->getConnection(), $connection);
 }
Exemple #2
0
 /**
  * Retrieve an attachment of a document.
  *
  * @param      string The name of the attachment.
  * @param      string|DocumentInterface The document or document ID.
  * @param      string The document revision.
  *                        
  * @return     string The new document revision.
  *
  * @author     Thomas Bachem <*****@*****.**>
  */
 public function deleteAttachment($name, $doc, $rev = null)
 {
     $con = $this->getConnection();
     if ($doc instanceof DocumentInterface) {
         $id = $doc->_id;
         if (!$rev) {
             $rev = $doc->_rev;
         }
     } else {
         $id = $doc;
     }
     if (strpos($id, '_') === 0) {
         throw new InvalidArgumentException('CouchDB document IDs must not start with an underscore.');
     }
     if (!$rev) {
         throw new InvalidArgumentException('Please supply a document revision to delete an attachment.');
     }
     $request = new HttpRequest($con->buildUrl(self::URL_PATTERN_ATTACHMENT, array($this->getName(), $id, $name)), HttpRequest::METHOD_DELETE);
     $request->setHeader('If-Match', $rev);
     $response = $con->sendRequest($request);
     $result = new Record($this->getConnection());
     $result->hydrate($response);
     if (isset($result->ok) && $result->ok === true) {
         return $result->rev;
     } else {
         throw new UnexpectedValueException('Deletion of the document failed.');
     }
 }