1
1
Fork 0

Replace api.yml to api.fixture.php

- Remove yaml dependency
- Add PHP array based fixture possibility
This commit is contained in:
Philipp Holzer 2019-07-28 20:46:29 +02:00
commit df9ebf5e8e
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
7 changed files with 278 additions and 281 deletions

View file

@ -1,50 +0,0 @@
<?php
namespace Friendica\Test\Util\Database;
use Friendica\Database\Database;
use Symfony\Component\Yaml\Yaml;
/**
* Util class to load YAML files into the database
*/
class YamlDataSet
{
/**
* @var array
*/
private $tables = [];
public function __construct(string $yamlFile)
{
$this->addYamlFile($yamlFile);
}
public function addYamlFile(string $yamlFile)
{
$data = Yaml::parse(file_get_contents($yamlFile));
foreach ($data as $tableName => $rows) {
if (!isset($rows)) {
$rows = [];
}
if (!is_array($rows)) {
continue;
}
foreach ($rows as $key => $value) {
$this->tables[$tableName][$key] = $value;
}
}
}
public function load(Database $database)
{
foreach ($this->tables as $tableName => $rows) {
foreach ($rows as $row) {
$database->insert($tableName, $row);
}
}
}
}