Skip to content

Commit

Permalink
Merge pull request #179 from josbeir/fixture-fixes
Browse files Browse the repository at this point in the history
Also use getName/getType from index on other fixture methods
  • Loading branch information
lorenzo authored Jun 29, 2018
2 parents cc7501a + 230a7ba commit e7b85f0
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/TestSuite/TestFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ public function init()
{
}

/**
* Return the index class from table name
*
* @return \Cake\ElasticSearch\Index
*/
public function getIndex()
{
$name = Inflector::camelize($this->table);

return IndexRegistry::get($name);
}

/**
* Create index and mapping for the type.
*
Expand All @@ -114,15 +126,13 @@ public function create(ConnectionInterface $db)
return;
}

$index = IndexRegistry::get(Inflector::camelize($this->table));

$esIndex = $db->getIndex($index->getName());
$esIndex = $db->getIndex($this->getIndex()->getName());
if ($esIndex->exists()) {
$esIndex->delete();
}
$esIndex->create();

$type = $esIndex->getType($index->getType());
$type = $esIndex->getType($this->getIndex()->getType());
$mapping = new ElasticaMapping();
$mapping->setType($type);
$mapping->setProperties($this->schema);
Expand Down Expand Up @@ -157,8 +167,8 @@ public function insert(ConnectionInterface $db)
return;
}
$documents = [];
$esIndex = $db->getIndex($this->table);
$type = $esIndex->getType(Inflector::singularize($this->table));
$esIndex = $db->getIndex($this->getIndex()->getName());
$type = $esIndex->getType($this->getIndex()->getType());

foreach ($this->records as $data) {
$id = '';
Expand All @@ -180,7 +190,7 @@ public function insert(ConnectionInterface $db)
*/
public function drop(ConnectionInterface $db)
{
$esIndex = $db->getIndex($this->table);
$esIndex = $db->getIndex($this->getIndex()->getName());

if ($esIndex->exists()) {
$esIndex->delete();
Expand All @@ -196,8 +206,8 @@ public function drop(ConnectionInterface $db)
public function truncate(ConnectionInterface $db)
{
$query = new MatchAll();
$esIndex = $db->getIndex($this->table);
$type = $esIndex->getType(Inflector::singularize($this->table));
$esIndex = $db->getIndex($this->getIndex()->getName());
$type = $esIndex->getType($this->getIndex()->getType());
$type->deleteByQuery($query);
$esIndex->refresh();
}
Expand Down

0 comments on commit e7b85f0

Please sign in to comment.