Browse Source

fixed test break

tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
31fece562e
  1. 3
      tests/unit/extensions/elasticsearch/ActiveRecordTest.php
  2. 31
      tests/unit/framework/ar/ActiveRecordTestTrait.php

3
tests/unit/extensions/elasticsearch/ActiveRecordTest.php

@ -47,6 +47,7 @@ class ActiveRecordTest extends ElasticSearchTestCase
if ($db->createCommand()->indexExists('yiitest')) { if ($db->createCommand()->indexExists('yiitest')) {
$db->createCommand()->deleteIndex('yiitest'); $db->createCommand()->deleteIndex('yiitest');
} }
$db->createCommand()->createIndex('yiitest');
$command = $db->createCommand(); $command = $db->createCommand();
Customer::setUpMapping($command); Customer::setUpMapping($command);
@ -54,6 +55,8 @@ class ActiveRecordTest extends ElasticSearchTestCase
Order::setUpMapping($command); Order::setUpMapping($command);
OrderItem::setUpMapping($command); OrderItem::setUpMapping($command);
$db->createCommand()->flushIndex('yiitest');
$customer = new Customer(); $customer = new Customer();
$customer->id = 1; $customer->id = 1;
$customer->setAttributes(['email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1], false); $customer->setAttributes(['email' => 'user1@example.com', 'name' => 'user1', 'address' => 'address1', 'status' => 1], false);

31
tests/unit/framework/ar/ActiveRecordTestTrait.php

@ -487,6 +487,37 @@ trait ActiveRecordTestTrait
public function testFindEagerViaRelationPreserveOrder() public function testFindEagerViaRelationPreserveOrder()
{ {
/** @var TestCase|ActiveRecordTestTrait $this */ /** @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(); $orders = $this->callOrderFind()->with('itemsInOrder1')->orderBy('create_time')->all();
$this->assertEquals(3, count($orders)); $this->assertEquals(3, count($orders));

Loading…
Cancel
Save