Skip to content

Commit

Permalink
DocumentsManager: add tests for crud operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dieterve committed Jun 26, 2015
1 parent fb4a8f0 commit 3266a2f
Showing 1 changed file with 79 additions and 2 deletions.
81 changes: 79 additions & 2 deletions tests/Managers/DocumentsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,83 @@ public function setUp()
$this->documentsManager = $this->getElasticSearcher()->documentsManager();
}

public function testIndex()
{
$id = 11111;
$data = [
'id' => $id,
'name' => 'The Guardians of the Galaxy',
'year' => 2015,
];

// Make sure the document doesn't exist.
if ($this->documentsManager->exists('movies', 'movies', $id)) {
$this->documentsManager->delete('movies', 'movies', $id);
}

$this->documentsManager->index('movies', 'movies', $data);
$this->assertTrue($this->documentsManager->exists('movies', 'movies', $id));
$this->assertEquals($data, $this->documentsManager->get('movies', 'movies', $id)['_source']);
}

public function testBulkIndex()
{
$documents = [
[
'id' => 111112,
'name' => 'The Guardians of the Galaxy',
'year' => 2015,
],
[
'id' => 111113,
'name' => 'Spiderman 4D',
'year' => 2015,
],
[
'id' => 111114,
'name' => 'Tokyo Drift',
'year' => 2013,
],
];

$this->documentsManager->bulkIndex('movies', 'movies', $documents);

foreach ($documents as $document) {
$this->assertTrue($this->documentsManager->exists('movies', 'movies', $document['id']));
$this->assertEquals($document, $this->documentsManager->get('movies', 'movies', $document['id'])['_source']);
}
}

public function testUpdate()
{
// Make sure a document exists.
$id = 33333;
$data = [
'id' => $id,
'name' => 'The Guardians of the Galaxy',
'year' => 1915,
];
$this->documentsManager->updateOrIndex('movies', 'movies', $id, $data);

$this->documentsManager->update('movies', 'movies', $id, ['year' => 2015]);
$this->assertEquals(2015, $this->documentsManager->get('movies', 'movies', $id)['_source']['year']);
}

public function testDelete()
{
// Make sure a document exists.
$id = 22222;
$data = [
'id' => $id,
'name' => 'The Guardians of the Galaxy',
'year' => 2015,
];
$this->documentsManager->updateOrIndex('movies', 'movies', $id, $data);

$this->documentsManager->delete('movies', 'movies', $id);
$this->assertFalse($this->documentsManager->exists('movies', 'movies', $id));
}

public function testUpdateOrIndex()
{
$id = 12345;
Expand All @@ -32,14 +109,14 @@ public function testUpdateOrIndex()
$this->documentsManager->updateOrIndex('movies', 'movies', $id, [
'id' => $id,
'name' => 'Jurasic World',
'year' => 2014
'year' => 2014,
]);
$this->assertTrue($this->documentsManager->exists('movies', 'movies', $id));

$this->documentsManager->updateOrIndex('movies', 'movies', $id, [
'id' => $id,
'name' => 'Jurasic World',
'year' => 2015
'year' => 2015,
]);
$document = $this->documentsManager->get('movies', 'movies', $id);
$this->assertEquals('2015', $document['_source']['year']);
Expand Down

0 comments on commit 3266a2f

Please sign in to comment.