/**
    * Test if we get an error back, if we violate a unique constraint
    */
   public function testCreateAndExecuteTransactionWithTransactionErrorUniqueConstraintOnSave()
   {
       if (isCluster($this->connection)) {
           // don't execute this test in a cluster
           return;
       }
       $writeCollections = array($this->collection1->getName());
       $readCollections = array($this->collection2->getName());
       $action = '
 function () {
   var db = require("internal").db;
   db.' . $this->collection1->getName() . '.save({ _key : "hello" });
   db.' . $this->collection1->getName() . '.save({ _key : "hello" });
 }';
       $transaction = new Transaction($this->connection);
       $transaction->setWriteCollections($writeCollections);
       $transaction->setReadCollections($readCollections);
       $transaction->setAction($action);
       $e = null;
       try {
           $transaction->execute();
       } catch (ServerException $e) {
       }
       $details = $e->getDetails();
       $expectedCutDownMessage = "unique constraint violated";
       $this->assertTrue($e->getCode() == 400 && strstr($details['errorMessage'], $expectedCutDownMessage) !== false, 'Did not return code 400 with first part of the message: "' . $expectedCutDownMessage . '", instead returned: ' . $e->getCode() . ' and "' . $details['errorMessage'] . '"');
   }
    /**
     * test for import of documents by giving an array of documents
     */
    public function testImportFromStringUsingDocumentsUsingResultset()
    {
        if (isCluster($this->connection)) {
            // don't execute this test in a cluster
            return;
        }
        $collectionHandler = $this->collectionHandler;
        $data = '[{ "firstName" : "Joe", "lastName" : "Public", "age" : 42, "gender" : "male", "_key" : "test1"},
{ "firstName" : "Jane", "lastName" : "Doe", "age" : 31, "gender" : "female", "_key" : "test2"}]';
        $result = $collectionHandler->import('importCollection_01_arango_unittests', $data, $options = array('createCollection' => true, 'type' => 'array'));
        $this->assertTrue($result['error'] === false && $result['created'] == 2);
        $statement = new Statement($this->connection, array("query" => '', "count" => true, "batchSize" => 1000, "sanitize" => true));
        $query = 'FOR u IN `importCollection_01_arango_unittests` SORT u._id ASC RETURN u';
        $statement->setQuery($query);
        $cursor = $statement->execute();
        $resultingDocument = null;
        foreach ($cursor as $key => $value) {
            $resultingDocument[$key] = $value;
        }
        $this->assertTrue($resultingDocument[0]->getKey() == 'test1' && $resultingDocument[0]->firstName == 'Joe', 'Document returned did not contain expected data.');
        $this->assertTrue($resultingDocument[1]->getKey() == 'test2' && $resultingDocument[1]->firstName == 'Jane', 'Document returned did not contain expected data.');
        $this->assertTrue(count($resultingDocument) == 2, 'Should be 2, was: ' . count($resultingDocument));
    }
 /**
  * Try to create a collection with specified shard keys
  */
 public function testCreateCollectionWithShardKeysCluster()
 {
     if (!isCluster($this->connection)) {
         // don't execute this test in a non-cluster
         return;
     }
     $connection = $this->connection;
     $collection = new Collection();
     $collectionHandler = new CollectionHandler($connection);
     $name = 'ArangoDB_PHP_TestSuite_TestCollection_01';
     try {
         $collectionHandler->drop($name);
     } catch (Exception $e) {
         //Silence the exception
     }
     $collection->setName($name);
     $collection->setShardKeys(array("_key", "a", "b"));
     $response = $collectionHandler->add($collection);
     $resultingCollection = $collectionHandler->getProperties($response);
     $properties = $resultingCollection->getAll();
     $this->assertEquals($properties[Collection::ENTRY_NUMBER_OF_SHARDS], 1, 'Number of shards does not match.');
     $this->assertEquals($properties[Collection::ENTRY_SHARD_KEYS], array("_key", "a", "b"), 'Shard keys do not match.');
 }