mirror of
https://github.com/friendica/friendica
synced 2025-04-25 19:10:11 +00:00
Remove Phpunit/Dbunit
- Introduce own Yaml-to-SQL class - Introduce new way of MySQL-DB-tests (per rollback) - Remove dependency phpunit/dbunit - Introduce new dev-dependency for YAML-ready (Symfony YAML reader)
This commit is contained in:
parent
eddcb5ebe9
commit
b08ac3c0a7
9 changed files with 771 additions and 429 deletions
50
tests/Util/Database/YamlDataSet.php
Normal file
50
tests/Util/Database/YamlDataSet.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue