-
-
Notifications
You must be signed in to change notification settings - Fork 251
/
Copy pathActiveQueryTest.php
45 lines (36 loc) · 1.27 KB
/
ActiveQueryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace yiiunit\extensions\elasticsearch;
use yiiunit\extensions\elasticsearch\data\ar\Item;
/**
* @group elasticsearch
*/
class ActiveQueryTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$command = $this->getConnection()->createCommand();
// delete index
if ($command->indexExists(Item::index())) {
$command->deleteIndex(Item::index());
}
Item::setUpMapping($command);
$command->insert(Item::index(), Item::type(), ['name' => 'item1', 'category_id' => 17], 1);
$command->refreshIndex(Item::index());
}
/**
* @throws \yii\elasticsearch\Exception
*/
public function testColumn()
{
$activeQuery = Item::find()->where(['name' => 'item1'])->asArray();
$result = $activeQuery->column('category_id', $this->getConnection());
$this->assertEquals([17], $result);
$result = $activeQuery->column('_id', $this->getConnection());
$this->assertEquals([1], $result);
$result = $activeQuery->column('noname', $this->getConnection());
$this->assertEquals([null], $result);
$result = $activeQuery->scalar('name', $this->getConnection());
$this->assertEquals('item1', $result);
}
}