Skip to content

Commit

Permalink
Fix 'ExportCursor' class
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassouzavieira committed Oct 31, 2019
1 parent afdcee5 commit ee7316b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Cursor/CollectionCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use ArangoDB\Document\Edge;
use ArangoDB\Document\Document;
use ArangoDB\Collection\Collection;
use ArangoDB\Validation\Exceptions\MissingParameterException;
use GuzzleHttp\Exception\GuzzleException;
use ArangoDB\Validation\Exceptions\MissingParameterException;
use ArangoDB\Validation\Exceptions\InvalidParameterException;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Cursor/ExportCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function __construct(Connection $connection, string $collection, array $o
throw new DatabaseException("Collection ($collection) doesn't exists.");
}

$this->collection = $connection->getDatabase()->getCollection($collection);
$this->uri = Api::addQuery(Api::EXPORT, ['collection' => $collection]);
$this->connection = $connection;
$this->result = new ArrayList();
Expand Down
4 changes: 2 additions & 2 deletions tests/Cursor/CollectionCursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testConstructorThrowCursorException()
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => [], 'name' => 'test_cursor_coll'])),
new Response(200, [], json_encode($this->getMockedCollection())),
new Response(200, [], json_encode(['result' => []])),
new Response(403, [], json_encode($this->mockServerError()))
]);
Expand All @@ -40,7 +40,7 @@ public function testFetch()
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => [], 'name' => 'test_cursor_coll'])),
new Response(200, [], json_encode($this->getMockedCollection())),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(array_merge(['result' => $this->getMockArray(1000), 'id' => '154875', 'hasMore' => true], $defaults))),
new Response(200, [], json_encode(array_merge(['result' => $this->getMockArray(1000), 'id' => '154875', 'hasMore' => true], $defaults))),
Expand Down
23 changes: 23 additions & 0 deletions tests/Cursor/CursorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ public function tearDown(): void
parent::tearDown();
}

public function getMockedCollection(string $name = 'test_cursor_coll')
{
return [
'error' => false,
'code' => 200,
'type' => 2,
'status' => 3,
'statusString' => 'loaded',
'id' => 156487,
'waitForSync' => false,
'objectId' => "359808",
'cacheEnabled' => false,
'isSystem' => false,
'globallyUniqueId' => 'hD2468C4BDA19/359806',
'keyOptions' => [
'allowUserKeys' => true,
'type' => "traditional",
'lastValue' => 0
],
'name' => $name
];
}

public function getCollection($quantity = 500)
{
$db = $this->getConnectionObject()->getDatabase();
Expand Down
16 changes: 13 additions & 3 deletions tests/Cursor/ExportCursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ public function testConstructorThrowCursorException()
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => [], 'name' => 'test_cursor_coll'])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode($this->getMockedCollection())),
new Response(200, [], json_encode(['result' => []])),
new Response(403, [], json_encode($this->mockServerError()))
]);

$connection = $this->getConnectionObject($mock);
$collection = $this->getConnectionObject($mock)->getDatabase()->createCollection('test_cursor_coll');
$collection = $connection->getDatabase()->createCollection('test_cursor_coll');

$this->expectException(CursorException::class);
$cursor = new ExportCursor($connection, 'test_cursor_coll');
Expand All @@ -51,7 +56,12 @@ public function testFetch()
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => [], 'name' => 'test_cursor_coll'])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode($this->getMockedCollection())),
new Response(200, [], json_encode(['result' => []])),
new Response(200, [], json_encode(array_merge(['result' => $this->getMockArray(1000), 'id' => '154875', 'hasMore' => true], $defaults))),
new Response(200, [], json_encode(array_merge(['result' => $this->getMockArray(1000), 'id' => '154875', 'hasMore' => true], $defaults))),
Expand Down
1 change: 0 additions & 1 deletion tests/Validation/Document/EdgeValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function testValidatorThrowMissingParameterExceptionForToParam()
$validator = new EdgeValidator($attributes);
$this->expectException(MissingParameterException::class);
$validator->validate();

}

public function testValidatorThrowMissingParameterExceptionForFromParam()
Expand Down

0 comments on commit ee7316b

Please sign in to comment.