Exemplo n.º 1
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]));
 }