Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test BaseActiveRecord::getOldAttribute() after insert and update
Browse files Browse the repository at this point in the history
Tigrov committed Dec 14, 2023
1 parent 41c6691 commit 4db8f9b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/ActiveQueryTest.php
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]',
'name' => 'Jack',
'address' => '123 Ocean Dr',
'status' => 1,
]);

$this->assertNull($customer->getOldAttribute('name'));
$this->assertTrue($customer->save());
$this->assertSame('Jack', $customer->getOldAttribute('name'));

$customer->name = 'Harry';

$this->assertTrue($customer->save());
$this->assertSame('Harry', $customer->getOldAttribute('name'));
}

public function testCheckRelationUnknownPropertyException(): void
{
$this->checkFixture($this->db, 'customer');

0 comments on commit 4db8f9b

Please sign in to comment.