Exemplo n.º 1
0
 public function testPaginator()
 {
     $resultSet = TestSchema::find();
     $paginator = new Paginator($resultSet, 10, 1);
     $this->assertInstanceOf('\\Reach\\Mongo\\Paginator', $paginator);
     $this->assertEquals(10, $paginator->getLimit());
     $this->assertEquals(1, $paginator->getCurrentPage());
     $this->assertInstanceOf('\\Reach\\Mongo\\ResultSet', $paginator->getResultSet());
     $paginator->setCurrentPage(2);
     $this->assertEquals(2, $paginator->getCurrentPage());
     $page = $paginator->getPaginate();
     $this->assertEquals(1, $page->first);
     $this->assertEquals(2, $page->current);
     $this->assertEquals(3, $page->next);
     $this->assertEquals(1, $page->prev);
     $this->assertEquals(10, $page->last);
     $this->assertEquals(10, $page->pages);
     $this->assertEquals(100, $page->total_items);
     $this->assertInstanceOf('\\Reach\\Mongo\\ResultSet', $page->items);
     $this->assertEquals('Title10', $page->items->first()->title);
 }
Exemplo n.º 2
0
 public function testAsArray()
 {
     $resultSet = TestSchema::find();
     $array = $resultSet->asArray();
     $this->assertEquals(0, key($array));
     $resultSet = TestSchema::find()->sort(['title' => 1]);
     $array = $resultSet->export(true);
     $this->assertEquals((string) $this->_ids[0], key($array));
 }
Exemplo n.º 3
0
 public function testFind()
 {
     $resultSet = TestSchema::find(['a' => 123]);
     $this->assertInstanceOf('\\Reach\\ResultSetInterface', $resultSet);
     $this->assertEquals(0, $resultSet->count());
     $cursor = TestSchema::find(['a' => 123], ['title']);
     $this->assertInstanceOf('\\MongoCursor', $cursor);
     $this->assertEquals(0, $cursor->count());
     $model = new TestSchema(['title' => 1, 'object' => ['a' => 1]]);
     $model->save();
     $model = new TestSchema(['title' => 2, 'object' => ['a' => 2]]);
     $model->save();
     $model = new TestSchema(['title' => 3, 'object' => ['a' => 2]]);
     $model->save();
     $resultSet = TestSchema::find(['title' => '111']);
     $this->assertInstanceOf('\\Reach\\Mongo\\ResultSet', $resultSet);
     $this->assertEquals(0, count($resultSet));
     $resultSet = TestSchema::find(['title' => ['$gt' => 1]]);
     $this->assertInstanceOf('\\Reach\\Mongo\\ResultSet', $resultSet);
     $this->assertEquals(2, count($resultSet));
     /** @var \MongoCursor $cursor */
     $cursor = TestSchema::find(['title' => ['$gt' => 1]], ['title']);
     $this->assertInstanceOf('\\MongoCursor', $cursor);
     $this->assertEquals(2, $cursor->count());
     $cursor->getNext();
     $array = $cursor->getNext();
     $this->assertFalse(isset($array['object']));
     // Schema::count
     $this->assertEquals(2, TestSchema::count(['object.a' => 2]));
     $this->assertEquals(0, TestSchema::count(['object.a' => 0]));
 }
Exemplo n.º 4
0
 /**
  * @iterations 500
  */
 public function findingAllByIndexFieldAndToArray()
 {
     $array = TestSchema::find(['object.type' => 1])->asArray();
     if (!count($array)) {
         throw new Exception(__METHOD__);
     }
 }