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); }
public function testNot() { $connection = $this->getConnection(); $query = new Query(); $rows = $query->from(Customer::tableName())->where(['not', 'status', ['>=' => 10]])->all($connection); $this->assertEquals(9, count($rows)); $query = new Query(); $rows = $query->from(Customer::tableName())->where(['not', 'name', 'name1'])->all($connection); $this->assertEquals(9, count($rows)); }
/** * @depends testInsert * */ public function testInsertEmptyAttributes() { $record = new Customer(); $record->save(false); $this->assertFalse($record->isNewRecord); }
public function getCustomer() { return $this->hasOne(Customer::className(), ['id' => 'customer_id']); }