From d56e02010957b2b01e7b179a8aad80838593634c Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 25 Nov 2013 14:07:30 +0100 Subject: [PATCH] more random test fixes --- tests/unit/extensions/elasticsearch/ActiveRecordTest.php | 4 ++-- tests/unit/framework/ar/ActiveRecordTestTrait.php | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/unit/extensions/elasticsearch/ActiveRecordTest.php b/tests/unit/extensions/elasticsearch/ActiveRecordTest.php index 69f9edb..ec5dd1a 100644 --- a/tests/unit/extensions/elasticsearch/ActiveRecordTest.php +++ b/tests/unit/extensions/elasticsearch/ActiveRecordTest.php @@ -33,7 +33,7 @@ class ActiveRecordTest extends ElasticSearchTestCase */ public function afterSave() { - $this->getConnection()->createCommand()->flushIndex(); + $this->getConnection()->createCommand()->flushIndex('yiitest'); } 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->save(false); - Customer::getDb()->createCommand()->flushIndex(); + $db->createCommand()->flushIndex('yiitest'); } public function testGetDb() diff --git a/tests/unit/framework/ar/ActiveRecordTestTrait.php b/tests/unit/framework/ar/ActiveRecordTestTrait.php index 4c33543..ba2d8e6 100644 --- a/tests/unit/framework/ar/ActiveRecordTestTrait.php +++ b/tests/unit/framework/ar/ActiveRecordTestTrait.php @@ -352,14 +352,17 @@ trait ActiveRecordTestTrait public function testFindEager() { /** @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->assertTrue($customers[0]->isRelationPopulated('orders')); $this->assertTrue($customers[1]->isRelationPopulated('orders')); - $this->assertEquals(1, count($customers[0]->orders)); - $this->assertEquals(2, count($customers[1]->orders)); + $this->assertTrue($customers[2]->isRelationPopulated('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->assertEquals(1, count($customer->orders)); $this->assertEquals(1, count($customer->populatedRelations));