diff --git a/tests/ActiveQueryTest.php b/tests/ActiveQueryTest.php index 5eda8f3c9..4fa25063b 100644 --- a/tests/ActiveQueryTest.php +++ b/tests/ActiveQueryTest.php @@ -2231,6 +2231,29 @@ public function testIsAttributeChangedNotIdentical(): void $this->assertTrue($query->isAttributeChanged('name', false)); } + public function testOldAttributeAfterInsertAndUpdate(): void + { + $this->checkFixture($this->db, 'customer'); + + $customer = new Customer($this->db); + + $customer->setAttributes([ + 'email' => 'info@example.com', + 'name' => 'Jack', + 'address' => '123 Ocean Dr', + 'status' => 1, + ]); + + $this->assertNull($customer->getOldAttribute('name')); + $this->assertTrue($customer->save()); + $this->assertSame('Jack', $customer->getOldAttribute('name')); + + $customer->setAttribute('name', 'Harry'); + + $this->assertTrue($customer->save()); + $this->assertSame('Harry', $customer->getOldAttribute('name')); + } + public function testCheckRelationUnknownPropertyException(): void { $this->checkFixture($this->db, 'customer');