Skip to content

Commit

Permalink
Fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed May 20, 2024
1 parent 11fc383 commit 34ba5fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
7 changes: 6 additions & 1 deletion src/BaseActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public function optimisticLock(): string|null
public function populateRecord(array|object $row): void
{
foreach ($row as $name => $value) {
$this->$name = $value;
$this->populateAttribute($name, $value);
$this->oldAttributes[$name] = $value;
}

Expand Down Expand Up @@ -1204,4 +1204,9 @@ public function getTableName(): string

return $this->tableName;
}

protected function populateAttribute(string $name, mixed $value): void

Check warning on line 1208 in src/BaseActiveRecord.php

View check run for this annotation

Codecov / codecov/patch

src/BaseActiveRecord.php#L1208

Added line #L1208 was not covered by tests
{
$this->$name = $value;

Check warning on line 1210 in src/BaseActiveRecord.php

View check run for this annotation

Codecov / codecov/patch

src/BaseActiveRecord.php#L1210

Added line #L1210 was not covered by tests
}
}
25 changes: 5 additions & 20 deletions src/Trait/MagicPropertiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,28 +193,13 @@ public function setAttribute(string $name, mixed $value): void
}
}

/**
* Populates an active record object using a row of data from the database/storage.
*
* This is an internal method meant to be called to create active record objects after fetching data from the
* database. It is mainly used by {@see ActiveQuery} to populate the query results into active records.
*
* @param array|object $row Attribute values (name => value).
*/
public function populateRecord(array|object $row): void
protected function populateAttribute(string $name, mixed $value): void
{
foreach ($row as $name => $value) {
if (property_exists($this, $name)) {
$this->$name = $value;
} else {
$this->attributes[$name] = $value;
}

$this->oldAttributes[$name] = $value;
if (property_exists($this, $name)) {
$this->$name = $value;
} else {
$this->attributes[$name] = $value;
}

$this->related = [];
$this->relationsDependencies = [];
}

/**
Expand Down

0 comments on commit 34ba5fd

Please sign in to comment.