mirror of
https://framagit.org/hubzilla/core.git
synced 2026-06-21 00:52:33 -04:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user