public function testIssues()
 {
     // https://github.com/yiisoft/yii2/issues/4938
     $category = Category::findOne(2);
     $this->assertTrue($category instanceof Category);
     $this->assertEquals(3, $category->getItems()->count());
     $this->assertEquals(1, $category->getLimitedItems()->count());
     $this->assertEquals(1, $category->getLimitedItems()->distinct(true)->count());
     // https://github.com/yiisoft/yii2/issues/3197
     $orders = Order::find()->with('orderItems')->orderBy('id')->all();
     $this->assertEquals(3, count($orders));
     $this->assertEquals(2, count($orders[0]->orderItems));
     $this->assertEquals(3, count($orders[1]->orderItems));
     $this->assertEquals(1, count($orders[2]->orderItems));
     $orders = Order::find()->with(['orderItems' => function ($q) {
         $q->indexBy('item_id');
     }])->orderBy('id')->all();
     $this->assertEquals(3, count($orders));
     $this->assertEquals(2, count($orders[0]->orderItems));
     $this->assertEquals(3, count($orders[1]->orderItems));
     $this->assertEquals(1, count($orders[2]->orderItems));
 }
예제 #2
0
 public function testIssues()
 {
     // https://github.com/yiisoft/yii2/issues/4938
     $category = Category::findOne(2);
     $this->assertTrue($category instanceof Category);
     $this->assertEquals(3, $category->getItems()->count());
     $this->assertEquals(1, $category->getLimitedItems()->count());
     $this->assertEquals(1, $category->getLimitedItems()->distinct(true)->count());
     // https://github.com/yiisoft/yii2/issues/3197
     $orders = Order::find()->with('orderItems')->orderBy('id')->all();
     $this->assertEquals(3, count($orders));
     $this->assertEquals(2, count($orders[0]->orderItems));
     $this->assertEquals(3, count($orders[1]->orderItems));
     $this->assertEquals(1, count($orders[2]->orderItems));
     $orders = Order::find()->with(['orderItems' => function ($q) {
         $q->indexBy('item_id');
     }])->orderBy('id')->all();
     $this->assertEquals(3, count($orders));
     $this->assertEquals(2, count($orders[0]->orderItems));
     $this->assertEquals(3, count($orders[1]->orderItems));
     $this->assertEquals(1, count($orders[2]->orderItems));
     // https://github.com/yiisoft/yii2/issues/8149
     $model = new Customer();
     $model->name = 'test';
     $model->email = 'test';
     $model->save(false);
     $model->updateCounters(['status' => 1]);
     $this->assertEquals(1, $model->status);
 }
예제 #3
0
 public function testIssues()
 {
     // https://github.com/yiisoft/yii2/issues/4938
     $category = Category::findOne(2);
     $this->assertTrue($category instanceof Category);
     $this->assertEquals(3, $category->getItems()->count());
     $this->assertEquals(1, $category->getLimitedItems()->count());
     $this->assertEquals(1, $category->getLimitedItems()->distinct(true)->count());
 }