From b74a2dff9e6b839f2a47e2dd36be78659faea7f3 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 9 Nov 2025 20:33:24 +0100 Subject: [PATCH] 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. --- tests/unit/UnitTestCase.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/unit/UnitTestCase.php b/tests/unit/UnitTestCase.php index e3cd22b63..6ab518336 100644 --- a/tests/unit/UnitTestCase.php +++ b/tests/unit/UnitTestCase.php @@ -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; } } }