public function testFindEager() { /* @var $orders CustomerOrder[] */ $orders = CustomerOrder::find()->with('customer')->all(); $this->assertCount(10, $orders); $this->assertTrue($orders[0]->isRelationPopulated('customer')); $this->assertTrue($orders[1]->isRelationPopulated('customer')); $this->assertTrue($orders[0]->customer instanceof Customer); $this->assertEquals((string) $orders[0]->customer->id, (string) $orders[0]->customer_id); $this->assertTrue($orders[1]->customer instanceof Customer); $this->assertEquals((string) $orders[1]->customer->id, (string) $orders[1]->customer_id); /* @var $customers Customer[] */ $customers = Customer::find()->with('orders')->all(); $this->assertCount(5, $customers); $this->assertTrue($customers[0]->isRelationPopulated('orders')); $this->assertTrue($customers[1]->isRelationPopulated('orders')); $this->assertNotEmpty($customers[0]->orders); $this->assertTrue($customers[0]->orders[0] instanceof CustomerOrder); $this->assertEquals((string) $customers[0]->id, (string) $customers[0]->orders[0]->customer_id); }
/** * @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); }