From 7654fff26d8c058e01f1c06e3210d9c5cb41e401 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 26 Dec 2013 12:39:38 -0500 Subject: [PATCH] Added unit test for ActiveRecord::updateAttributes(). --- tests/unit/framework/ar/ActiveRecordTestTrait.php | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/unit/framework/ar/ActiveRecordTestTrait.php b/tests/unit/framework/ar/ActiveRecordTestTrait.php index 95def9d..43cb52a 100644 --- a/tests/unit/framework/ar/ActiveRecordTestTrait.php +++ b/tests/unit/framework/ar/ActiveRecordTestTrait.php @@ -671,6 +671,40 @@ trait ActiveRecordTestTrait $this->assertEquals(0, $ret); } + public function testUpdateAttributes() + { + $customerClass = $this->getCustomerClass(); + /** @var TestCase|ActiveRecordTestTrait $this */ + // save + $customer = $this->callCustomerFind(2); + $this->assertTrue($customer instanceof $customerClass); + $this->assertEquals('user2', $customer->name); + $this->assertFalse($customer->isNewRecord); + static::$afterSaveNewRecord = null; + static::$afterSaveInsert = null; + + $customer->updateAttributes(['name' => 'user2x']); + $this->afterSave(); + $this->assertEquals('user2x', $customer->name); + $this->assertFalse($customer->isNewRecord); + $this->assertFalse(static::$afterSaveNewRecord); + $this->assertFalse(static::$afterSaveInsert); + $customer2 = $this->callCustomerFind(2); + $this->assertEquals('user2x', $customer2->name); + + $customer = $this->callCustomerFind(1); + $this->assertEquals('user1', $customer->name); + $this->assertEquals(1, $customer->status); + $customer->name = 'user1x'; + $customer->status = 2; + $customer->updateAttributes(['name']); + $this->assertEquals('user1x', $customer->name); + $this->assertEquals(2, $customer->status); + $customer = $this->callCustomerFind(1); + $this->assertEquals('user1x', $customer->name); + $this->assertEquals(1, $customer->status); + } + public function testUpdateCounters() { $orderItemClass = $this->getOrderItemClass();