From 230a7ba2c88c221cff122aadd33cac7554c2880d Mon Sep 17 00:00:00 2001 From: Jasper Smet Date: Fri, 29 Jun 2018 12:19:54 +0200 Subject: [PATCH] Also use getName/getType from index on other fixture methods --- src/TestSuite/TestFixture.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/TestSuite/TestFixture.php b/src/TestSuite/TestFixture.php index 6f56670e..f626f180 100644 --- a/src/TestSuite/TestFixture.php +++ b/src/TestSuite/TestFixture.php @@ -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. * @@ -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); @@ -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 = ''; @@ -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(); @@ -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(); }