Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions UNITTESTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# PHPUnit Tests for ArangoDB-PHP

To run the unit tests, cd into the tests folder and run:

<code>
phpunit --testsuite ArangoDB-PHP
</code>


###Changelog:

2012-10-06 : Some tests are failing because of issue https://github.com/triAGENS/ArangoDB/issues/220

2012-10-06 : Initial Commit. This first batch covers most important parts of:
- Connection
- Collection
- CollectionHandler
- Document
- Documenthandler
- Statements

14 changes: 14 additions & 0 deletions lib/triagens/ArangoDb/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
* @package ArangoDbPhpClient
*/
class Connection {
/**
* Api Version
* @var string
*/
public static $_apiVersion = '0.3.1';

/**
* Connection options
* @var array
Expand Down Expand Up @@ -257,4 +263,12 @@ private function executeRequest($method, $url, $data) {
throw new ClientException('Whoops, this should never happen');
}

/**
* Get the client api version
*
* @return string
*/
public static function getVersion() {
return self::$_apiVersion;
}
}
60 changes: 60 additions & 0 deletions tests/CollectionBasicTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* ArangoDB PHP client testsuite
* File: collectionbasictest.php
*
* @package ArangoDbPhpClient
* @author Frank Mayer
*/

namespace triagens\ArangoDB;

class CollectionBasicTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->connection = getConnection();
}

/**
* Test if Collection and CollectionHandler instances can be initialized
*/
public function testInitializeCollection()
{
$connection = $this->connection;
$collection = new \triagens\ArangoDb\Collection();
$this->assertInstanceOf('triagens\ArangoDB\Collection', $collection);
$collectionHandler = new \triagens\ArangoDb\CollectionHandler($connection);
$this->assertInstanceOf('triagens\ArangoDB\Collection', $collection);
}

/**
* Try to create and delete a collection
*/
public function testCreateAndDeleteCollection()
{
$connection = $this->connection;
$collection = new \triagens\ArangoDb\Collection();
$collectionHandler = new \triagens\ArangoDb\CollectionHandler($connection);

$name = 'ArangoDB-PHP-TestSuite-TestCollection-01';
$collection->setName($name);

$response = $collectionHandler->add($collection);

$this->assertTrue(is_numeric($response), 'Did not return a numeric id!');

$resultingCollection = $collectionHandler->get($response);

$resultingAttribute = $resultingCollection->getName();
$this->assertTrue($name === $resultingAttribute, 'The created collection name and resulting collection name do not match!');

$response = $collectionHandler->delete($collection);
}

public function tearDown()
{
unset($this->connection);
}
}
117 changes: 117 additions & 0 deletions tests/CollectionExtendedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
/**
* ArangoDB PHP client testsuite
* File: collectionextendedtest.php
*
* @package ArangoDbPhpClient
* @author Frank Mayer
*/

namespace triagens\ArangoDB;

class CollectionExtendedTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->connection = getConnection();
$this->collection = new \triagens\ArangoDb\Collection();
$this->collectionHandler = new \triagens\ArangoDb\CollectionHandler($this->connection);
}

/**
* test for creation, get, and delete of a collection with waitForSync default value (no setting)
*/
public function testCreateAndDeleteCollectionWithWaitForSyncDefault()
{
$collection = $this->collection;
$collectionHandler = $this->collectionHandler;

$resultingAttribute = $collection->getWaitForSync();
print_r($resultingAttribute);
$this->assertTrue(null === $resultingAttribute, 'Default waitForSync in API should be NULL!');

$collection->setName('ArangoDB-PHP-TestSuite-TestCollection-01');

$response = $collectionHandler->add($collection);

$this->assertTrue(is_numeric($response), 'Adding collection did not return an id!');

$resultingCollection = $collectionHandler->get($response);

$resultingAttribute = $resultingCollection->getWaitForSync();
$this->assertTrue(false === $resultingAttribute, 'Default Server waitForSync should return false!');

$response = $collectionHandler->delete($collection);
$this->assertTrue(true === $response, 'Delete should return true!');
}

/**
* test for creation, get, and delete of a collection with waitForSync set to true
*/
public function testCreateGetAndDeleteCollectionWithWaitForSyncTrue()
{
$collection = $this->collection;
$collectionHandler = $this->collectionHandler;

$collection->setWaitForSync(true);
$resultingAttribute = $collection->getWaitForSync();
$this->assertTrue(true === $resultingAttribute, 'WaitForSync should be true!');
$collection->setName('ArangoDB-PHP-TestSuite-TestCollection-01');

$response = $collectionHandler->add($collection);

$resultingCollection = $collectionHandler->get($response);

$resultingAttribute = $resultingCollection->getWaitForSync();
$this->assertTrue(true === $resultingAttribute, 'Server waitForSync should return true!');

$response = $collectionHandler->delete($collection);
$this->assertTrue(true === $response, 'Delete should return true!');
}

/**
* test for creation, get, and delete of a collection given its settings through createFromArray()
*/
public function testCreateGetAndDeleteCollectionThroughCreateFromArrayWithWaitForSyncTrue()
{
$collectionHandler = $this->collectionHandler;

$collection = Collection::createFromArray(array('name' => 'ArangoDB-PHP-TestSuite-TestCollection-01', 'waitForSync' => true));
$response = $collectionHandler->add($collection);

$resultingCollection = $collectionHandler->get($response);

$resultingAttribute = $resultingCollection->getWaitForSync();
$this->assertTrue(true === $resultingAttribute, 'Server waitForSync should return true!');

$response = $collectionHandler->delete($collection);
$this->assertTrue(true === $response, 'Delete should return true!');
}

/**
* test to set some attributes and get all attributes of the collection through getAll()
*/
public function testGetAll()
{
$collection = Collection::createFromArray(array('name' => 'ArangoDB-PHP-TestSuite-TestCollection-01', 'waitForSync' => true));
$result = $collection->getAll();

$this->assertArrayHasKey('id', $result, 'Id field should exist, empty or with an id');
$this->assertTrue(true === ($result['name'] == 'ArangoDB-PHP-TestSuite-TestCollection-01'), 'name should return ArangoDB-PHP-TestSuite-TestCollection-01!');
$this->assertTrue(true === ($result['waitForSync'] == true), 'waitForSync should return true!');

}

public function tearDown()
{
try {
$response = $this->collectionHandler->delete('ArangoDB-PHP-TestSuite-TestCollection-01');
} catch (\Exception $e) {
// don't bother us, if it's already deleted.
}

unset($this->collectionHandler);
unset($this->collection);
unset($this->connection);
}
}
32 changes: 32 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* ArangoDB PHP client testsuite
* File: connectiontest.php
*
* @package ArangoDbPhpClient
* @author Frank Mayer
*/

namespace triagens\ArangoDB;

class ConnectionTest extends \PHPUnit_Framework_TestCase
{
/**
* Test if Connection instance can be initialized
*/
public function testInitializeConnection()
{
$connection = getConnection();
$this->assertInstanceOf('triagens\ArangoDB\Connection', $connection);
}

/**
* This is just a test to really test connectivity with the server before moving on to further tests.
*/
public function testGetStatus()
{
$connection = getConnection();
$response = $connection->get('/_admin/status');
$this->assertTrue($response->getHttpCode() == 200, 'Did not return http code 200');
}
}
77 changes: 77 additions & 0 deletions tests/DocumentBasicTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* ArangoDB PHP client testsuite
* File: documentbasictest.php
*
* @package ArangoDbPhpClient
* @author Frank Mayer
*/

namespace triagens\ArangoDB;

class DocumentBasicTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->connection = getConnection();
$this->collectionHandler = new \triagens\ArangoDb\CollectionHandler($this->connection);
$this->collection = new \triagens\ArangoDb\Collection();
$this->collection->setName('ArangoDB-PHP-TestSuite-TestCollection-01');
$this->collectionHandler->add($this->collection);
}

/**
* Test if Document and DocumentHandler instances can be initialized
*/
public function testInitializeDocument()
{
$connection = $this->connection;
$this->collection = new \triagens\ArangoDb\Collection();
$this->collectionHandler = new \triagens\ArangoDb\CollectionHandler($this->connection);
$document = new \triagens\ArangoDb\Document();
$this->assertInstanceOf('triagens\ArangoDB\Document', $document);
$this->assertInstanceOf('triagens\ArangoDB\Document', $document);
unset ($document);
}

/**
* Try to create and delete a document
*/
public function testCreateAndDeleteDocument()
{
$connection = $this->connection;
$collection = $this->collection;
$collectionHandler = $this->collectionHandler;
$document = new \triagens\ArangoDb\Document();
$documentHandler = new \triagens\ArangoDb\DocumentHandler($connection);

$document->someAttribute = 'someValue';

$documentId = $documentHandler->add($collection->getId(), $document);

print_r($documentId);

$resultingDocument = $documentHandler->get($collection->getId(), $documentId);

$resultingAttribute = $resultingDocument->someAttribute;
$this->assertTrue($resultingAttribute === 'someValue', 'Created document id is not numeric!');

$response = $documentHandler->delete($document);
}

public function tearDown()
{
try {
$response = $this->collectionHandler->delete('ArangoDB-PHP-TestSuite-TestCollection-01');
} catch (\Exception $e) {
// don't bother us, if it's already deleted.
}


unset($this->documentHandler);
unset($this->document);
unset($this->collectionHandler);
unset($this->collection);
unset($this->connection);
}
}
Loading