public function testActiveQuery()
 {
     $provider = new ActiveDataProvider(['query' => Customer::find()->orderBy('id ASC')]);
     $models = $provider->getModels();
     $this->assertEquals(10, count($models));
     $this->assertTrue($models[0] instanceof Customer);
     $keys = $provider->getKeys();
     $this->assertTrue($keys[0] instanceof \MongoId);
     $provider = new ActiveDataProvider(['query' => Customer::find(), 'pagination' => ['pageSize' => 5]]);
     $models = $provider->getModels();
     $this->assertEquals(5, count($models));
 }
 public function testFindEager()
 {
     /* @var $customers Customer[] */
     $customers = Customer::find()->with('file')->all();
     $this->assertEquals(5, count($customers));
     $this->assertTrue($customers[0]->isRelationPopulated('file'));
     $this->assertTrue($customers[1]->isRelationPopulated('file'));
     $this->assertTrue($customers[0]->file instanceof CustomerFile);
     $this->assertEquals((string) $customers[0]->file->_id, (string) $customers[0]->file_id);
     $this->assertTrue($customers[1]->file instanceof CustomerFile);
     $this->assertEquals((string) $customers[1]->file->_id, (string) $customers[1]->file_id);
 }
Example #3
0
 protected function tearDown()
 {
     $this->dropCollection(Customer::collectionName());
     $this->dropCollection(CustomerOrder::collectionName());
     parent::tearDown();
 }
 /**
  * @depends testInsert
  *
  * @see https://github.com/yiisoft/yii2/issues/6026
  */
 public function testInsertEmptyAttributes()
 {
     $record = new Customer();
     $record->save(false);
     $this->assertTrue($record->_id instanceof \MongoId);
     $this->assertFalse($record->isNewRecord);
 }
Example #5
0
 /**
  * @depends testFind
  * @depends testInsert
  */
 public function testQueryByIntegerField()
 {
     $record = new Customer();
     $record->name = 'new name';
     $record->status = 7;
     $record->save();
     $row = Customer::find()->where(['status' => 7])->one();
     $this->assertNotEmpty($row);
     $this->assertEquals(7, $row->status);
     $rowRefreshed = Customer::find()->where(['status' => $row->status])->one();
     $this->assertNotEmpty($rowRefreshed);
     $this->assertEquals(7, $rowRefreshed->status);
 }