Browse Source

more random test fixes

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

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

@ -33,7 +33,7 @@ class ActiveRecordTest extends ElasticSearchTestCase
*/ */
public function afterSave() public function afterSave()
{ {
$this->getConnection()->createCommand()->flushIndex(); $this->getConnection()->createCommand()->flushIndex('yiitest');
} }
public function setUp() public function setUp()
@ -129,7 +129,7 @@ class ActiveRecordTest extends ElasticSearchTestCase
$orderItem->setAttributes(['order_id' => 3, 'item_id' => 2, 'quantity' => 1, 'subtotal' => 40.0], false); $orderItem->setAttributes(['order_id' => 3, 'item_id' => 2, 'quantity' => 1, 'subtotal' => 40.0], false);
$orderItem->save(false); $orderItem->save(false);
Customer::getDb()->createCommand()->flushIndex(); $db->createCommand()->flushIndex('yiitest');
} }
public function testGetDb() public function testGetDb()

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

@ -352,14 +352,17 @@ trait ActiveRecordTestTrait
public function testFindEager() public function testFindEager()
{ {
/** @var TestCase|ActiveRecordTestTrait $this */ /** @var TestCase|ActiveRecordTestTrait $this */
$customers = $this->callCustomerFind()->with('orders')->all(); $customers = $this->callCustomerFind()->with('orders')->indexBy('id')->all();
ksort($customers);
$this->assertEquals(3, count($customers)); $this->assertEquals(3, count($customers));
$this->assertTrue($customers[0]->isRelationPopulated('orders'));
$this->assertTrue($customers[1]->isRelationPopulated('orders')); $this->assertTrue($customers[1]->isRelationPopulated('orders'));
$this->assertEquals(1, count($customers[0]->orders)); $this->assertTrue($customers[2]->isRelationPopulated('orders'));
$this->assertEquals(2, count($customers[1]->orders)); $this->assertTrue($customers[3]->isRelationPopulated('orders'));
$this->assertEquals(1, count($customers[1]->orders));
$this->assertEquals(2, count($customers[2]->orders));
$this->assertEquals(0, count($customers[3]->orders));
$customer = $this->callCustomerFind()->with('orders')->one(); $customer = $this->callCustomerFind()->where(['id' => 1])->with('orders')->one();
$this->assertTrue($customer->isRelationPopulated('orders')); $this->assertTrue($customer->isRelationPopulated('orders'));
$this->assertEquals(1, count($customer->orders)); $this->assertEquals(1, count($customer->orders));
$this->assertEquals(1, count($customer->populatedRelations)); $this->assertEquals(1, count($customer->populatedRelations));

Loading…
Cancel
Save