|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * ArangoDB PHP client testsuite |
| 4 | + * File: Database.php |
| 5 | + * |
| 6 | + * @package ArangoDBClient |
| 7 | + * @author Frank Mayer |
| 8 | + */ |
| 9 | + |
| 10 | +namespace ArangoDBClient; |
| 11 | + |
| 12 | +/** |
| 13 | + * Class DatabaseTest |
| 14 | + * Basic Tests for the Database API implementation |
| 15 | + * |
| 16 | + * @property Connection $connection |
| 17 | + * |
| 18 | + * @package ArangoDBClient |
| 19 | + */ |
| 20 | +class CustomEdgeClassTest extends |
| 21 | + \PHPUnit_Framework_TestCase |
| 22 | +{ |
| 23 | + |
| 24 | + protected static $testsTimestamp; |
| 25 | + |
| 26 | + protected $collection; |
| 27 | + protected $collectionHandler; |
| 28 | + |
| 29 | + public function __construct($name = null, array $data = [], $dataName = '') |
| 30 | + { |
| 31 | + parent::__construct($name, $data, $dataName); |
| 32 | + static::$testsTimestamp = str_replace('.', '_', (string) microtime(true)); |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | + public function setUp() |
| 37 | + { |
| 38 | + $this->connection = getConnection(); |
| 39 | + $this->collectionHandler = new CollectionHandler($this->connection); |
| 40 | + |
| 41 | + try { |
| 42 | + $this->collectionHandler->drop('ArangoDB_PHP_TestSuite_TestCollection_01'); |
| 43 | + } catch (\Exception $e) { |
| 44 | + // don't bother us, if it's already deleted. |
| 45 | + } |
| 46 | + |
| 47 | + $this->collection = new Collection(); |
| 48 | + $this->collection->setName('ArangoDB_PHP_TestSuite_TestCollection_01' . '_' . static::$testsTimestamp); |
| 49 | + $this->collection->setType('edge'); |
| 50 | + $this->collectionHandler->create($this->collection); |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + /** |
| 55 | + * Try to retrieve an edge with custom document class |
| 56 | + */ |
| 57 | + public function testGetCustomEdgeWithHandler() |
| 58 | + { |
| 59 | + $connection = $this->connection; |
| 60 | + $collection = $this->collection; |
| 61 | + $edge = new Edge(); |
| 62 | + $edgeHandler = new EdgeHandler($connection); |
| 63 | + |
| 64 | + $edge->someAttribute = 'someValue'; |
| 65 | + $edge->setFrom('test/v1'); |
| 66 | + $edge->setTo('test/v2'); |
| 67 | + $documentId = $edgeHandler->saveEdge($collection->getName(), 'test/v1', 'test/v2', $edge); |
| 68 | + |
| 69 | + $edgeHandler->setEdgeClass(CustomEdgeClass1::class); |
| 70 | + $resultingEdge1 = $edgeHandler->get($collection->getName(), $documentId); |
| 71 | + static::assertInstanceOf(CustomEdgeClass1::class, $resultingEdge1, 'Retrieved edge isn\'t made with provided CustomEdgeClass1!'); |
| 72 | + |
| 73 | + $edgeHandler->setEdgeClass(CustomEdgeClass2::class); |
| 74 | + $resultingEdge2 = $edgeHandler->get($collection->getName(), $documentId); |
| 75 | + static::assertInstanceOf(CustomEdgeClass2::class, $resultingEdge2, 'Retrieved edge isn\'t made with provided CustomEdgeClass2!'); |
| 76 | + |
| 77 | + $edgeHandler->setEdgeClass(Edge::class); |
| 78 | + $resultingEdge = $edgeHandler->get($collection->getName(), $documentId); |
| 79 | + static::assertInstanceOf(Edge::class, $resultingEdge, 'Retrieved edge isn\'t made with provided Edge!'); |
| 80 | + static::assertNotInstanceOf(CustomEdgeClass1::class, $resultingEdge, 'Retrieved edge is made with CustomEdgeClass1!'); |
| 81 | + static::assertNotInstanceOf(CustomEdgeClass2::class, $resultingEdge, 'Retrieved edge is made with CustomEdgeClass2!'); |
| 82 | + |
| 83 | + $resultingAttribute = $resultingEdge->someAttribute; |
| 84 | + static::assertSame('someValue', $resultingAttribute); |
| 85 | + static::assertSame('test/v1', $resultingEdge->getFrom()); |
| 86 | + static::assertSame('test/v2', $resultingEdge->getTo()); |
| 87 | + |
| 88 | + $resultingAttribute1 = $resultingEdge1->someAttribute; |
| 89 | + static::assertSame('someValue', $resultingAttribute1); |
| 90 | + static::assertSame('test/v1', $resultingEdge1->getFrom()); |
| 91 | + static::assertSame('test/v2', $resultingEdge1->getTo()); |
| 92 | + |
| 93 | + $resultingAttribute2 = $resultingEdge2->someAttribute; |
| 94 | + static::assertSame('someValue', $resultingAttribute2); |
| 95 | + static::assertSame('test/v1', $resultingEdge2->getFrom()); |
| 96 | + static::assertSame('test/v2', $resultingEdge2->getTo()); |
| 97 | + |
| 98 | + $edgeHandler->remove($edge); |
| 99 | + } |
| 100 | + |
| 101 | + public function tearDown() |
| 102 | + { |
| 103 | + try { |
| 104 | + $this->collectionHandler->drop('ArangoDB_PHP_TestSuite_TestCollection_01' . '_' . static::$testsTimestamp); |
| 105 | + } catch (\Exception $e) { |
| 106 | + // don't bother us, if it's already deleted. |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | +} |
| 111 | + |
| 112 | +class CustomEdgeClass1 extends Edge |
| 113 | +{ |
| 114 | +} |
| 115 | + |
| 116 | +class CustomEdgeClass2 extends Edge |
| 117 | +{ |
| 118 | +} |
0 commit comments