Skip to content

Commit 961c7f4

Browse files
committed
Added a test to make sure that the _flat option is respected and returns the correct data and format
1 parent 0d48802 commit 961c7f4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/CollectionExtendedTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,38 @@ public function testCreateDocumentsWithCreateFromArrayAndRemoveByExample()
775775
static::assertSame($result, 2);
776776
}
777777

778+
/**
779+
* test for creation of documents, and removal by example
780+
*/
781+
public function testCreateDocumentsWithCreateFromArrayGetAsArrayAndRemoveByExample()
782+
{
783+
$documentHandler = $this->documentHandler;
784+
$collectionHandler = $this->collectionHandler;
785+
786+
$collection = Collection::createFromArray(
787+
['name' => 'ArangoDB_PHP_TestSuite_TestCollection_01', 'waitForSync' => true]
788+
);
789+
$collectionHandler->create($collection);
790+
$document = Document::createFromArray(
791+
['someAttribute' => 'someValue1', 'someOtherAttribute' => 'someOtherValue']
792+
);
793+
$documentId = $documentHandler->save($collection->getId(), $document);
794+
$documentArray = $document->getAll(['_includeInternals' => false]);
795+
796+
$exampleDocument = Document::createFromArray(['someOtherAttribute' => 'someOtherValue']);
797+
$cursor = $collectionHandler->byExample($collection->getId(), $exampleDocument, ['_flat' => true]);
798+
799+
$array = $cursor->getAll();
800+
801+
static::assertArrayHasKey('_key', $array[0]);
802+
static::assertArrayHasKey('_id', $array[0]);
803+
static::assertArrayHasKey('_rev', $array[0]);
804+
805+
unset($array[0]['_key'], $array[0]['_id'], $array[0]['_rev']);
806+
807+
static::assertSame($array[0], $documentArray);
808+
}
809+
778810

779811
/**
780812
* test for creation of documents, and update and replace by example and finally removal by example

0 commit comments

Comments
 (0)