mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-24 16:07:19 +01:00
Fixes #13467: yii\data\ActiveDataProvider no longer queries models if models count is zero
This commit is contained in:
committed by
Alexander Makarov
parent
ecd2dc0d1b
commit
7d82bbcd37
@@ -7,12 +7,14 @@
|
||||
|
||||
namespace yiiunit\framework\data;
|
||||
|
||||
use yii\base\InvalidCallException;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\Query;
|
||||
use yiiunit\data\ar\ActiveRecord;
|
||||
use yiiunit\data\ar\Customer;
|
||||
use yiiunit\data\ar\Item;
|
||||
use yiiunit\framework\db\DatabaseTestCase;
|
||||
use yiiunit\framework\db\UnqueryableQueryMock;
|
||||
use yiiunit\data\ar\Order;
|
||||
|
||||
/**
|
||||
@@ -177,4 +179,23 @@ abstract class ActiveDataProviderTest extends DatabaseTestCase
|
||||
$provider->refresh();
|
||||
$this->assertEquals(2, count($provider->getModels()));
|
||||
}
|
||||
|
||||
public function testDoesNotPerformQueryWhenHasNoModels()
|
||||
{
|
||||
$query = new UnqueryableQueryMock;
|
||||
$provider = new ActiveDataProvider([
|
||||
'db' => $this->getConnection(),
|
||||
'query' => $query->from('order')->where('0=1'),
|
||||
]);
|
||||
$pagination = $provider->getPagination();
|
||||
$this->assertEquals(0, $pagination->getPageCount());
|
||||
|
||||
try {
|
||||
$this->assertCount(0, $provider->getModels());
|
||||
} catch (InvalidCallException $exception) {
|
||||
$this->fail('An excessive models query was executed.');
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $pagination->getPageCount());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user