Reload test fixtures from db

Reload inserted rows from the DB when loading the test fixtures. This
ensures that we get all default fields and id columns initialized and
validated. Some code under test will require this to work as expected.
This commit is contained in:
Harald Eilertsen
2025-11-09 20:33:24 +01:00
parent 6400bcc81f
commit b74a2dff9e

View File

@@ -22,6 +22,7 @@
namespace Zotlabs\Tests\Unit;
use DBA;
use PHPUnit\Framework\Attributes\{Before, After};
use PHPUnit\Framework\TestCase;
@@ -182,16 +183,11 @@ class UnitTestCase extends TestCase {
*/
private function loadFixture($file) : void {
$table_name = basename($file, '.yml');
$this->fixtures[$table_name] = yaml_parse_file($file)[$table_name];
$data = yaml_parse_file($file)[$table_name];
foreach ($this->fixtures[$table_name] as $entry) {
$query = 'INSERT INTO ' . dbesc($table_name) . '('
. implode(',', array_keys($entry))
. ') VALUES('
. implode(',', array_map(fn($val) => "'{$val}'", array_values($entry)))
. ')';
q($query);
foreach ($data as $entry) {
$row = DBA::$dba->insert($table_name, $entry);
$this->fixtures[$table_name][] = $row;
}
}
}