Skip to content

Commit

Permalink
Test BaseActiveRecord::getOldAttribute() after insert and update (#277
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Tigrov authored Dec 16, 2023
1 parent c78469c commit 6d9864b
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
Expand Up @@ -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->setAttribute('name', 'Harry');

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

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

0 comments on commit 6d9864b

Please sign in to comment.