private function prepare() { $cities = ['New York', 'Tokyo', 'Los Angeles', 'Paris', 'Shanghai', 'Shanghai', 'Shanghai', 'Shanghai', 'Shanghai', 'Shanghai', 'Shanghai', 'New Delhi', 'New Hempshire']; foreach ($cities as $city) { $model = new SimpleModel(); $model->_id = new MongoId(); $model->title = $city; $im = new IndexManager($model); $im->index(); } // Need to wait here, or it will fail... sleep(1); return $model; }
public function testIfWillFindDocument() { $model = new SimpleModel(); $model->_id = new MongoId(); $model->title = 'New York, Tokyo, Los Angeles, Paris, Shanghai'; $im = new IndexManager($model); $im->index(); $val = $im->get(); // Need to wait here, or it will fail... sleep(1); $q = new QueryBuilder($model); /* @var $result SimpleModel[] */ $result = $q->search('tokyo'); codecept_debug($result); $this->assertTrue(count($result) > 0); unset($result); }
public function testIfWillSkipNonSearchableField() { $model = new ExplicitlyNonIndexableField(); $model->_id = new MongoId(); $model->title = 'Jersey'; $model->password = '******'; $model->details = 'some secret details'; $im = new IndexManager($model); $im->index(); $found = $im->get(); /* @var $found ExplicitlyNonIndexableField */ codecept_debug($found); $this->assertInstanceOf(ExplicitlyNonIndexableField::class, $found); $this->assertSame($model->title, $found->title); codecept_debug($found->password); $this->assertTrue(empty($found->password), 'That password was not indexed'); codecept_debug($found->details); $this->assertTrue(empty($found->details), 'That details field was not indexed'); }
public function testIfWillDropIndex() { $model = new SimpleModel(); $model->_id = new MongoId(); $model->title = 'Jersey'; $im = new IndexManager($model); $im->index(); $found = $im->get(); // Check if is indexed $this->assertTrue($found instanceof SimpleModel); $this->assertSame($model->title, $found->title); $result = Manganel::create($model)->drop(); codecept_debug($result); try { $im->get(); $this->assertFalse(true); } catch (Missing404Exception $ex) { $this->assertTrue(true); } }
public function testIfIndexManagerCanCreateRetrieveUpdateDelete() { $model = new SimpleModel(); $model->_id = new MongoId(); $model->title = 'Jersey'; $im = new IndexManager($model); $im->index(); $found = $im->get(); $this->assertTrue($found instanceof SimpleModel); $this->assertSame($model->title, $found->title); $model->title = 'New York, New York'; $im->index(); $found = $im->get(); $this->assertTrue($found instanceof SimpleModel); $this->assertSame($model->title, $found->title); $im->delete(); try { $im->get(); $this->assertFalse(true); } catch (Missing404Exception $ex) { $this->assertTrue(true); } }