diff --git a/tests/unit/extensions/elasticsearch/ActiveRecordTest.php b/tests/unit/extensions/elasticsearch/ActiveRecordTest.php index 2d31792..8d3db69 100644 --- a/tests/unit/extensions/elasticsearch/ActiveRecordTest.php +++ b/tests/unit/extensions/elasticsearch/ActiveRecordTest.php @@ -47,6 +47,7 @@ class ActiveRecordTest extends ElasticSearchTestCase if ($db->createCommand()->indexExists('yiitest')) { $db->createCommand()->deleteIndex('yiitest'); } + $db->createCommand()->createIndex('yiitest'); $command = $db->createCommand(); Customer::setUpMapping($command); @@ -54,6 +55,8 @@ class ActiveRecordTest extends ElasticSearchTestCase Order::setUpMapping($command); OrderItem::setUpMapping($command); + $db->createCommand()->flushIndex('yiitest'); + $customer = new Customer(); $customer->id = 1; $customer->setAttributes(['email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1], false); diff --git a/tests/unit/framework/ar/ActiveRecordTestTrait.php b/tests/unit/framework/ar/ActiveRecordTestTrait.php index e54df3f..338217b 100644 --- a/tests/unit/framework/ar/ActiveRecordTestTrait.php +++ b/tests/unit/framework/ar/ActiveRecordTestTrait.php @@ -487,6 +487,37 @@ trait ActiveRecordTestTrait public function testFindEagerViaRelationPreserveOrder() { /** @var TestCase|ActiveRecordTestTrait $this */ + + /* + Item (name, category_id) + Order (customer_id, create_time, total) + OrderItem (order_id, item_id, quantity, subtotal) + + Result should be the following: + + Order 1: 1, 1325282384, 110.0 + - orderItems: + OrderItem: 1, 1, 1, 30.0 + OrderItem: 1, 2, 2, 40.0 + - itemsInOrder: + Item 1: 'Agile Web Application Development with Yii1.1 and PHP5', 1 + Item 2: 'Yii 1.1 Application Development Cookbook', 1 + + Order 2: 2, 1325334482, 33.0 + - orderItems: + OrderItem: 2, 3, 1, 8.0 + OrderItem: 2, 4, 1, 10.0 + OrderItem: 2, 5, 1, 15.0 + - itemsInOrder: + Item 5: 'Cars', 2 + Item 3: 'Ice Age', 2 + Item 4: 'Toy Story', 2 + Order 3: 2, 1325502201, 40.0 + - orderItems: + OrderItem: 3, 2, 1, 40.0 + - itemsInOrder: + Item 3: 'Ice Age', 2 + */ $orders = $this->callOrderFind()->with('itemsInOrder1')->orderBy('create_time')->all(); $this->assertEquals(3, count($orders));